Isnull和''在sql查询中的混淆 [英] confusion in Isnull and ' ' in sql query

查看:100
本文介绍了Isnull和''在sql查询中的混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

heyy ..



我对Isnull查询感到困惑...



在我的桌子上我有一个空白值的字段(客户名称).........当我写这样的查询时..



heyy..

I am confused with Isnull query ...

IN my table I have a field(customer Name) with a blank value......... when i write query like this..

select * from dbo.M_CustomerMasterDetails
where
CustomerMasterId=281 and (
 CustomerName = is null;
 PartyCode =is null)





我没有得到结果....



但是当我写查询链接时这个..







I don't get the result ....

But when I write query link this..


select * from dbo.M_CustomerMasterDetails
where
CustomerMasterId=281 and (
 CustomerName = ''
 PartyCode ='')





我得到了结果...







什么是差异b / w为空和''在sql中。 .....



I got result...



what is the diffrence b/w is null and ' ' in sql......

推荐答案

Null表示该值未知。



''表示有一个值,并且它是一个空字符串。



如果你的数据库允许CustomerName和PartyCode字段的空值,您需要在查询中检查它们。一种选择是:



Null means the value is unknown.

'' means that there is a value, and that it's an empty string.

If your database allows nulls for the CustomerName and PartyCode fields, you would need to check for them in your query. One option would be this:

select * from dbo.M_CustomerMasterDetails
where
CustomerMasterId= 281 and (
 isnull(CustomerName, '') = ''
 or isnull(PartyCode, '') = '')





As除此之外,您的查询中存在语法错误。这可能会解决您的一些问题。



As an aside, there are syntax errors in your queries above. That might account for some of your issues.


这篇关于Isnull和''在sql查询中的混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆