27,579
社区成员
发帖
与我相关
我的任务
分享
--> --> (Roy)生成測試數據
if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([ID] int,[Type] int)
Insert #T
select null,1 union all
select null,1 union all
select null,2 union all
select null,3 union all
select null,1 union all
select null,3 union all
select null,2
Go
declare @1 int,@2 int,@3 int
select @1=50000,@2=60000,@3=70000
update #T
set ID=case when [Type]=1 then @1 when [Type]=2 then @2 when [Type]=3 then @3 end
,@1=case when [Type]=1 then @1+1 else @1 end
,@2=case when [Type]=2 then @2+1 else @2 end
,@3=case when [Type]=3 then @3+1 else @3 end
select * from #T order by Type,ID
ID Type
----------- -----------
50001 1
50002 1
50003 1
60001 2
60002 2
70001 3
70002 3
(7 行受影响)