Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Null Problem

Author  Topic 

mike1973
Starting Member

46 Posts

Posted - 2011-11-15 : 05:06:43
Hello friends,

i have this query it should return the max value for the billnumber

SELECT MAX(BillNUmber) as MAXNUBMR
FROM Bills
WHERE ClientID=@ClientID and Hidden=0

the problem is how to i replace the returned NULL value with a 0?

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-15 : 05:12:48
SELECT ISNULL(MAX(BillNUmber),0) as MAXNUBMR
FROM Bills
WHERE ClientID=@ClientID and Hidden=0



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-11-15 : 10:54:13
As Madhivanan has shown you can use the ISNULL function. There is also the COALESCE function, which I beleive is ANSI 99 compliant, if that matters:

http://msdn.microsoft.com/en-us/library/ms190349.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-15 : 11:02:43
see the comparison details here

http://beyondrelational.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-11-15 : 14:22:02
You can
SELECT ISNULL(MAX(BillNUmber),0) as MAXNUBMR
FROM Bills
WHERE ClientID=@ClientID and Hidden=0

or you can
As Madhivanan has shown you can use the ISNULL function. There is also the COALESCE function, which I beleive is ANSI 99 compliant, if that matters:

please mark this answer as accepted if it helped you!

(yea, i miss the guy, just picking up the slack )

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -