sqlserver 临时表的使用示例
|
admin
2026年10月17日 12:53
本文热度 47
|
declare @customerID INTdeclare @curBelong intcreate table #ttableName(id int identity(1,1),customerID INT,oldBelongId INT)declare @n int,@rows int
insert #ttableName(customerID,oldBelongId) SELECT s.TableId,s.OldValue FROM sy_OperateLog s WHERE OperateType in (22,21,23,24) AND OldValue in('1457','1903','1837','194') AND Operatetime >= '2023-04-24';
select @rows =@@rowcount set @n=1 while @n<=@rowsbegin select @customerID=customerID,@curBelong=oldBelongId from #ttableName where id=@n
update CustomerPool set BelongId=@curBelong where Id=@customerID; insert into sy_OperateLog values(1,@customerID,0,GETDATE(),10,@curBelong,@curBelong,'归属销售',0,0); INSERT INTO kh_CustomerBelong VALUES (@customerID, @curBelong, 84, '0', '0', 0, NULL, 1, GETDATE());
print (@customerID) select @n=@n+1enddrop table #ttableName
该文章在 2026/10/17 12:53:34 编辑过