CREATE PROCEDURE [dbo].[sp_MES_JTMSLS]
--创建存储过程
as
BEGIN
BEGIN TRAN Tran_MoveData --开始事务
DECLARE @tran_error int;
declare @DQSJ datetime
set @DQSJ=GETDATE()
SET @tran_error = 0;
BEGIN TRY
insert into
JTMSLS(DJGUID,JTBH,DQCD,SDCD,ZCD,CJSJ)
select NEWID()
,JTBH
,DQCD
,SDCD
,ZCD
,CJSJ
from JTMS with (nolock) where DATEDIFF(HOUR,cjsj,@DQSJ)>=24 and DATEDIFF(HOUR,cjsj,@DQSJ)<=48; --转存数据
delete from JTMS where DATEDIFF(HOUR,cjsj,@DQSJ)>=24 and DATEDIFF(HOUR,cjsj,@DQSJ)<=48; --删除原数
END TRY
BEGIN CATCH
SET @tran_error = @tran_error + 1
PRINT ERROR_MESSAGE()
RETURN
END CATCH
IF(@tran_error > 0)
BEGIN
ROLLBACK TRAN;--回滚
END
ELSE
BEGIN
COMMIT TRAN;--提交
END
END
标签:cjsj,DQSJ,END,HOUR,--,BEGIN,Server,SQL,转存
From: https://www.cnblogs.com/SuSVIP/p/17074721.html