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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 If no record set to 0

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2012-05-22 : 12:16:15

Most of the time, there will be no record in the LEFT OUTER JOIN BELOW

SELECT 
tbl1.Name,
tblJOIN.Code

FROM MyTable tbl1
LEFT OUTER JOIN MyJoinTable tblJOIN on tblJOIN.ID = tbl1.ID


So, if tblJOIN.Code comes back empty or null, set it to 0.

Just can't seem to get the syntax right to set it to 0.

Thanks!!!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-05-22 : 12:17:55
SELECT
tbl1.Name,
ISNULL(tblJOIN.Code,0)

FROM MyTable tbl1
LEFT OUTER JOIN MyJoinTable tblJOIN on tblJOIN.ID = tbl1.ID

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -