查询结果如下:
id m1 m2 m3 m4 m5
01 15 2 7 null null
02 15 4 3 5 2
03 1 5 7 33 null要求得到:
02 15 12 3 5 2
03 1 5 7 33 null把M4,M5都为NULL的排除
id m1 m2 m3 m4 m5
01 15 2 7 null null
02 15 4 3 5 2
03 1 5 7 33 null要求得到:
02 15 12 3 5 2
03 1 5 7 33 null把M4,M5都为NULL的排除
insert into @T select '01',15,2,7,null,null
union all select '02',15,4,3,5,2
union all select '03',1,5,7,33,null
select * from @Tselect * from @T where m4 is not null or m5 is not null
SELECT * FROM (你第一个结果的查询语句)
WHERE m4 IS NOT NULL AND m5 IS NOT NULL
或用
isnull
M4 is not null and M5 is not null
--
M4,M5为字符时可用
isnull(M4,'')+isnull(M5,'')>''