Click here to Skip to main content
15,913,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..

SQL
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..


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


I got result...



what is the diffrence b/w is null and ' ' in sql......
Posted
Comments
SLNS001 11-Jun-13 0:38am    
I think, we can't use NULL in where clause.

1 solution

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:

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


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900