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)
 test for condition greater than 0 fails

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-09-24 : 03:23:30
Hello,
Am trying to test some values. But they arent giving the desired results


declare @present_credits numeric(18,4), @counter_local numeric(18,4), @counter_intl numeric(18,4)
set @counter_local = 10
set @counter_local = 50
set @present_credits = 60
if (( @present_credits - @counter_local )>=0 and ( @present_credits - @counter_intl)>=0)
begin
print 'Correct'
print @present_credits
print @counter_local
print @counter_intl
end
else
begin
print 'Failed'
print @present_credits
print @counter_local
print @counter_intl
end



Only results am getting is Failed

RESULTS

Failed
60.0000
50.0000



_____________________


Yes O !

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-09-24 : 03:29:22
You haven't given @counter_intl a value, rather assigning @counter_local twice. Since @counter_intl wasn't given a value, it's NULL and null always returns false when compared with anything.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 03:33:08
its correct according to your code. You've not set value for @counter_intl so it will be NULL. So if condition will fail and you will get only else part values.You will not get any value for @counter_intl as it is NULL.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 03:34:12
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-24 : 03:58:16
Also rewite your IF statement like this

if @present_credits >= @counter_local and @present_credits >= @counter_intl



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-09-24 : 04:22:13
silly me.

I need to cut back on the coffee

_____________________


Yes O !
Go to Top of Page
   

- Advertisement -