日期:2014-05-18  浏览次数:20529 次

去掉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的排除



------解决方案--------------------
select * from [table] where m4 is not null and m5 is not null
------解决方案--------------------
declare @T table(id varchar(5),m1 int,m2 int,m3 int,m4 int,m5 int)
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 @T

select * from @T where m4 is not null or m5 is not null
------解决方案--------------------


select * from tb where m4 is not null and m5 is not null
------解决方案--------------------
用子查询好了
SELECT * FROM (你第一个结果的查询语句) 
WHERE m4 IS NOT NULL AND m5 IS NOT NULL
------解决方案--------------------
M4 is not null or M5 is not null
或用
isnull

------解决方案--------------------
满足两个条件时用
M4 is not null and M5 is not null 
--
M4,M5为字符时可用
isnull(M4,'')+isnull(M5,'')>''