Author |
Topic |
msc_timor
Starting Member
11 Posts |
Posted - 2007-04-21 : 01:44:45
|
hi, i have two tables with similar data i.e one table has sales data and other table has sales return datawhat i want to do is join these two tables in select statement and want the net value in one column(sales-salesreturn). fine, but the problem lies here, some data are NULL so subtaction is not possible. so how can i change NULL to 0 (zero)plz find me a solution thanks |
|
spejbl
Starting Member
28 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2007-04-21 : 02:13:50
|
We use COALESCE(YourColumn,0) here, instead of ISNULL, because that is Ansi standard.FWIW Coalesce lets you use multiple expressions, so:COALESCE(PrimaryTable.MyColumn, SecondaryTable.AnotherColumn, 0)there are also some subtle issues with IsNull() when implicit Casting is invoked between different types.Kristen |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-21 : 02:16:39
|
another point in favor of coalesce is that it's harder to spell, so it makes you a better speller. www.elsasoft.org |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-04-21 : 02:29:29
|
Ha! Not to mention the fact that IsNull() implies a return value of True/False rather than "Return that first value that is NOT null ... |
 |
|
msc_timor
Starting Member
11 Posts |
Posted - 2007-04-21 : 05:12:06
|
hi, thanx, isnull worked fine for methanx 'gain |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-21 : 11:34:48
|
blatantly refusing our advice! the impudence! www.elsasoft.org |
 |
|
herothecat
Starting Member
19 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2007-04-21 : 13:11:49
|
Most of the differences I regard as Negatives against ISNULL().But for my money I would not want to have a mixture of the two through our code, and because we sometimes want multiple parameters we have standardised on COALESCE()Kristen |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-21 : 21:19:22
|
not to mention datatype precedence...declare @i1 intdeclare @v1 bigintselect coalesce(@i1, @v1, 1111111111111111111)select isnull(@i1, 1111111111111111111)select isnull(@v1, 1111111111111111111) Edit:ok... it's in the article... haven't read it before posting... _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-04-22 : 06:23:46
|
"Edit:ok... it's in the article... haven't read it before posting..."And the thread "there are also some subtle issues with IsNull() when implicit Casting is invoked between different types."... you're getting old old-boy!Kristen |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-22 : 11:57:28
|
looks like it yes.... or i can blame it on posting at 2:30 amI'm going to be silent about my state at the time _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|