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 2000 Forums
 SQL Server Development (2000)
 Null value -- help

Author  Topic 

thanksfor help
Posting Yak Master

106 Posts

Posted - 2007-08-02 : 15:03:18
Hi,

I have following situation

declare @a decimal(18,0)
declare @b decimal(18,0)
declare @c decimal(18,2)

set @a = 2
set @b = 2
set @c = 0

select case when ((@a - @b) > @c) then 0 end

In the case when @a and @b have the same value, I get the answer NULL and not 0.

Please advice what I am doing wrong here. I need to get the value 0.

Any help is very much appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-08-02 : 15:08:12
select case when ((@a - @b) >= @c) then 0 end

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-02 : 15:08:27
select case when ((@a - @b) > @c) then 0 else 0 end

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-02 : 15:08:42


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

thanksfor help
Posting Yak Master

106 Posts

Posted - 2007-08-02 : 15:14:50
thank youuuuuuuuuuuuuuuuuu very much, >= did the magic
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-08-06 : 11:55:49
why wouldnt you use the isnull function here ?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-08-06 : 12:17:18
quote:
Originally posted by Jim77

why wouldnt you use the isnull function here ?




It's not needed. The CASE was simply missing an ELSE clause, causing NULLS to be returned.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -