34,588
社区成员
发帖
与我相关
我的任务
分享
SELECT c5 = (
IF c1 NOT NULL AND c3 IS NULL THEN c1
IF c1 IS NULL AND c3 NOT NULL THEN c3
IF c1 NOT NULL AND c3 NOT NULL THEN c1 + c3
ELSE NULL)
FROM Test
--這種寫法說IF附近語法錯誤
declare @tb table (t1 int,t2 int,cc int)
insert into @tb select 1,2,null
update @tb set cc=case
when t1 is not null and t2 is null then t1
when t1 is null and t2 is not null then t2
when t1 is not null and t2 is not null then t1+t2
else null end
select * from @tb
如果是与:
if a = 1 and b = 1 and c = 1 ....
如果是或
if a = 1 or b = 1 or c = 1
如果与和或都有,用括号分开
if ( a = 1 and b = 1 ) or c = 1