日期:2014-05-17 浏览次数:20443 次
--1\ update B set col2=(case when b.col=1 then 值1 else when b.col=2 then 值2 end) from B a inner join B b on a.id=b.id --2\ create proc test as if col1=1 begin update B set col2=值1 end else begin update B set col2=值2 end
------解决方案--------------------
update tb set col1 = case col2 when 1 then 情况1的值 else 情况2的值 end
------解决方案--------------------
我不知道你干嘛不结贴,上面的人大部分回复都是正确的,除了我的之外,刚好在别的贴里面找到了可以用来测试的数据。顺便完善一下,免得以为我乱回帖:
CREATE TABLE [dbo].[station]( [AreaNo] [float] NULL, [RoadNo] [float] NULL, [stationno] [float] NULL, [StationName] [nvarchar](255) NULL) insert into station select 4407,61,-1,'麻所' insert into station select 4407,61,0,'威所' insert into station select 4407,61,1,'麻1' insert into station select 4407,61,2,'麻2' insert into station select 4407,61,3,'麻3' insert into station select 4407,61,4,'麻4' insert into station select 4407,61,5,'威1' insert into station select 4407,61,6,'威2' insert into station select 4407,61,7,'威3' insert into station select 4407,61,8,'威4' SELECT * FROM station UPDATE station SET roadno=(CASE WHEN stationno=1 THEN 123 ELSE 234 END ) FROM station