数据库中有Status,DateOfPost这两个字段需要当做查询条件来查询,
这两个字段中的数据类型都为nvarchar,并且是可以为空的,
现在这两个字段中包含3类数据:“正常数据”,“空字符串”,“NULL”,
现在我想查询,表中这两列没有数据的列查询出来,请问这个条件要怎么写?
------最佳解决方案--------------------
空字符串不叫没有数据,你要清楚什么是t-sql的3值逻辑。不过既然你“觉得”是没有数据,那就改一下:
where isnull(Status,'')='' and isnull(DateOfPost,'')=''
------其他解决方案--------------------
select * from 表 where rtrim(isnull(字段,''))=''
------其他解决方案--------------------
SELECT *
FROM 表
WHERE (Status IS NULL OR Status='') AND (DateOfPost IS NULL OR DateOfPost='')
------其他解决方案--------------------
没有数据仅仅是指null而不是空字符串吧?
------其他解决方案--------------------
where isnull(Status,'')='' and isnull(DateOfPost,'')=''
------其他解决方案--------------------
where isnull(Status,'')='' and isnull(DateOfPost,'')=''
还是
where isnull(Status,'')='' or isnull(DateOfPost,'')=''
管他是空字符串还是null,先都整成' '
你自己选一个吧
------其他解决方案--------------------
where Status is null and DateOfPost is null
------其他解决方案--------------------
NULL是没有数据,空字符串也是没有数据啊。。。。