随机数字,值,值在sql中的应用

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  <Author,,ljq>
-- Create date: <Create Date,,2015-02-14>
-- Description: <Description,,自动生成一个月的冷藏温湿度记录或者温湿度记录>
-- =============================================
ALTER PROCEDURE  AutoWSDorLcWSD
 -- Add the parameters for the stored procedure here
 @type int,
 @depoid char(10) =null,
 @userid char(10)=null,
 @begindate datetime =null,
 @enddate datetime =null
AS
BEGIN
  if @type =1
 begin
  if exists(select * from zGspWSDRecord where convert(char(10),dtm,120) = convert(char(10),getdate(),120))
  begin
   RAISERROR (N'这个月已存在计划,不需要生成',16,1)
   return
  end
  
  --set @begindate= DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
  --set @enddate = DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
  while (@begindate<@enddate)
  begin
   declare @AMTemp int --温度,
   declare @AMHum int --湿度
   declare @AMWether int
   select @AMWether =cast(floor(rand(checksum(newid()))*3+0) as int)
   select
   case
   when @AMWether =0 then '晴'
   when @AMWether =1 then '阴'
   when @AMWether =2 then '雨'
   end
   set @AMTemp= cast(floor(rand(checksum(newid()))*12+4) as int)
   set @AMHum=cast(floor(rand(checksum(newid()))*10+40) as int)
   --直接插入值
   insert into zGspWSDRecord(depoid,dtm,flagid,AMWether,AMTemp,AMHum,AMDoMethod,AMCheID,PMTemp,PMHum,PMDoMethod,PMWether,makdtm)
      values(@depoid,@begindate,'0',@AMWether,@AMTemp,@AMHum,'无',@userid,@AMTemp,@AMHum,'无',@AMWether,@begindate)
   set @begindate = DATEADD(dd,1,@begindate )
  end
  
 end
 --冷藏温湿度计划生成
 else if @type =2
 begin
  if exists(select * from zGspWSDRecord where convert(char(10),dtm,120) = convert(char(10),getdate(),120))
  begin
   RAISERROR (N'这个月已存在计划,不需要生成',16,1)
   return
  end
  
  while (@begindate<@enddate)
  begin
   --declare @lAMTemp int --温度,
   declare @lAMAfterTemp int --处理后温度
   --set @lAMTemp= cast(floor(rand(checksum(newid()))*12+4) as int)
   set @lAMAfterTemp=cast(floor(rand(checksum(newid()))*4+5) as int)
   --直接插入值
   select * from zGspLcWsdRecord
   insert into zGspLcWsdRecord(depoid,dtm,flagid,AMTemp,AMDoMethod,AMAfterTemp,AMakDtm,AMCheID,PMTemp,PMDoMethod,PMAfterTemp,PMakDtm,PMCheID)
    values(@depoid,@begindate,'0',@lAMAfterTemp,'',@lAMAfterTemp,@begindate,@userid,@lAMAfterTemp,'',@lAMAfterTemp,@begindate,@userid)
   set @begindate = DATEADD(dd,1,@begindate )
  end
  
 end
END
GO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员阿卢

谢谢鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值