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 2005 Forums
 Transact-SQL (2005)
 Evaluating Nulls as Zeros when INSERT INTO #Table?

Author  Topic 

mrgr8avill
Starting Member

16 Posts

Posted - 2007-07-21 : 22:30:22
Hello,

Another ignorant question, I am sure (I apologize). I have a stored procedure that stores data in to temporary tables, then pulls those tables together in another select, drops the tables, and returns the select.

Trouble is, there are some circumstances when I have NULL values, and I really would like to evaluate them to zero.

Since the temporary tables being created are both temporary and dynamic, I can't really script their creation (I have to rely on the INSERT INTOs).

Is there any way to end up with zeros instead of nulls?

Example of SP:

select (subquery1 as a, subquery2 as b...) into #temptableone
select (subquery33 as a, subquery 34 as b...) into #temptable two

select () #temtableone inner join temptabletwo on about 20 things

drop #temptableone
drop #temptabletwo


THANKS!!!!!!!!!!!!

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-21 : 23:28:38
When you do the SELECT <columnlist> INTO #tmp, use the COALESCE function to return a 0 instead of NULL.

SELECT col1, COALESCE(Col2,0), col3
INTO #tmp1
FROM ...




Alternatively, you can do this in your final SELECT too using the same COALESCE function above.
Finally, you can do it at your front end too.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -