现在的位置: 首页 > 综合 > 正文

Sql:语句:Update when case

2017年12月15日 ⁄ 综合 ⁄ 共 435字 ⁄ 字号 评论关闭

根据随机数来更新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

抱歉!评论已关闭.