-- ================================================
-- 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
-- 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