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
 IF operator in select

Author  Topic 

vasu4us
Posting Yak Master

102 Posts

Posted - 2007-02-14 : 15:03:31
Is it possible to write a select statement using IF operator just as we use CASE

Case WHEN #1 IS NULL THEN #0
WHEN #0<=#1 and #1 IS NOT NULL THEN #0
when #0>#1 and #1 IS NOT NULL THEN #1
End

can we do the same using if, this is what i did and failed
IF #1 is NOT NULL THEN
IF #0<#1 THEN #0 Else #1 END
ELSE #0
End

Thanks in Adv


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-14 : 15:06:59
Yes, but not as a part of the SELECT query.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-02-14 : 15:07:08
No, and why would you want to when CASE does what you want.
Go to Top of Page

vasu4us
Posting Yak Master

102 Posts

Posted - 2007-02-14 : 15:12:10
i nedd that for writing a function in a report and if it works i have to impliment it in many other
Peso u got it correct i wanted it to work with select and now i know its not possible i have to go with CASE

Thanks Guys
Go to Top of Page
   

- Advertisement -