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 Value

Author  Topic 

issam
Starting Member

30 Posts

Posted - 2007-08-29 : 14:42:29
Hi,
I have the following two cursor getting a result table #myresult. the fields ylmdb,ylmcr in table #mycursor is a numeric fields but on the second table become a char with a value of null. How to keep the fields with zero value.


declare @bal decimal(19,3)
set @bal = 0

select year,acctno,sum(lmdb+cmdb) as lydb,sum(lmcr+cmcr) as lycr, @bal as ylmdb,@bal as ylmcr
into #mycursor
from bmaster
where year = 2005
group by acctno,year

select acctno,year,
ylmdb = (SELECT #mycursor.lydb-#mycursor.lycr WHERE #mycursor.lydb > #mycursor.lycr),
ylmcr = (SELECT #mycursor.lycr-#mycursor.lydb WHERE #mycursor.lydb < #mycursor.lycr)
into #myresult
from #mycursor
order by acctno

select * from #myresult

thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-29 : 14:45:42
ISNULL(Col1, 0)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-08-29 : 14:45:50
Make use of ISNULL or COALESCE().

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -