34,838
社区成员




--上面写错了.
create table tb (F1 int, F2 int, F3 int, F4 int, F5 int)
insert into tb values( 1, 2, 3, 4, 1 )
insert into tb values( 5, 6, 7, 8, 2 )
go
select f5 ,
f1 = case when f5 = 1 then f1 else f2 end ,
f2 = case when f5 = 2 then f4 else f3 end
from tb
drop table tb
/*
f5 f1 f2
----------- ----------- -----------
1 1 3
2 6 8
(所影响的行数为 2 行
*/
create table tb (F1 int, F2 int, F3 int, F4 int, F5 int)
insert into tb values( 1, 2, 3, 4, 1 )
insert into tb values( 5, 6, 7, 8, 2 )
go
select f5 ,
f1 = case when f5 = 1 then f1 else f3 end ,
f2 = case when f5 = 2 then f2 else f4 end
from tb
drop table tb
/*
f5 f1 f2
----------- ----------- -----------
1 1 4
2 7 6
(所影响的行数为 2 行)
*/
select f5 ,
f1 = case when f5 = 1 then f1 else f3 end ,
f2 = case when f5 = 2 then f2 else f4 end
from tb