SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace null with '0' in query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

stuckne1
Starting Member

USA
22 Posts

Posted - 10/08/2010 :  11:47:22  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8764 Posts

Posted - 10/08/2010 :  11:49:07  Show Profile  Visit webfred's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 10/08/2010 :  11:49:54  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
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

Edited by - Transact Charlie on 10/08/2010 11:50:16
Go to Top of Page

jcelko
Esteemed SQL Purist

USA
547 Posts

Posted - 10/08/2010 :  16:03:40  Show Profile  Visit jcelko's Homepage  Reply with Quote
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

USA
5072 Posts

Posted - 10/08/2010 :  16:57:53  Show Profile  Visit russell's Homepage  Reply with Quote
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

USA
22 Posts

Posted - 10/09/2010 :  22:15:48  Show Profile  Reply with Quote
Alright, thanks guys!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000