天天看点

Sql:语句:Update when case

根据随机数来更新Comment ID

declare @indextable table(id int,names nvarchar(10),vs int,commentID int) insert into @indextable(id,names,vs,commentID) select 1,'zr',null,null union all select 2,'ld',null,null union all select 3,'wcb',null,null union all select 4, 'pdc',null,null  select * from @indextable

update @indextable set vs=1 where id in(1,3) select * from @indextable

update @indextable  set commentID = case when round(rand(),0)=1 then  30 else null end where id in(1,3)

select * from @indextable