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
 replace null with '0' in query

Author  Topic 

stuckne1
Starting Member

22 Posts

Posted - 2010-10-08 : 11:47:22
Hi, I'm trying to replace the null values in the results query with a '0' for Order_Id.

This is what I have so far but every time I go past this point it doesn't work...

SELECT CUSTOMER_t.Customer_Name, CUSTOMER_t.Customer_Id, Order_Id
FROM CUSTOMER_t LEFT OUTER JOIN ORDER_t ON CUSTOMER_t.Customer_Id = ORDER_t.CUSTOMER_Id

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-08 : 11:49:07
isnull(Order_Id,'0') as Order_Id


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-08 : 11:49:54
Use ISNULL or COLAESCE

SELECT CUSTOMER_t.Customer_Name, CUSTOMER_t.Customer_Id, ISNULL(Order_Id, 0) AS [Order_Id]
FROM CUSTOMER_t LEFT OUTER JOIN ORDER_t ON CUSTOMER_t.Customer_Id = ORDER_t.CUSTOMER_Id


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2010-10-08 : 16:03:40
Look up COALESCE(); it isw ANSI/ISO Standard.

Do not use the proprietary ISNULL(); they are not the same

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-08 : 16:57:53
No, not the same, but there's no reason not to use isnull unless you're planning on porting everything to a different platform.

As with all code, it becomes proprietary as soon as developers start writing it for their applications.
Go to Top of Page

stuckne1
Starting Member

22 Posts

Posted - 2010-10-09 : 22:15:48
Alright, thanks guys!
Go to Top of Page
   

- Advertisement -