[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

lesleyann76

3/29/2007 1:24:00 PM

In Sql, is there the equivalent of an "if" conditional statement? For
instance, in Access I might use IIf([ShippingStatus] = 9, [ShipDate],
"Delayed"). IIf(Condition, True, False).

4 Answers

Uri Dimant

3/29/2007 1:29:00 PM

0

Hi

Its called CASE expression, for more details see BOL

BTW , there is IF cond. statement in SQL Server also:-))


<lesleyann76@gmail.com> wrote in message
news:1175174618.262103.43070@r56g2000hsd.googlegroups.com...
> In Sql, is there the equivalent of an "if" conditional statement? For
> instance, in Access I might use IIf([ShippingStatus] = 9, [ShipDate],
> "Delayed"). IIf(Condition, True, False).
>


unknown

3/29/2007 1:29:00 PM

0

<lesleyann76@gmail.com> wrote in message
news:1175174618.262103.43070@r56g2000hsd.googlegroups.com...
> In Sql, is there the equivalent of an "if" conditional statement? For
> instance, in Access I might use IIf([ShippingStatus] = 9, [ShipDate],
> "Delayed"). IIf(Condition, True, False).

CASE WHEN Condion THEN ShipDate ELSE "Delayed" END

You can have multiple WHENs statements also. But you might be better using
the ISNULL(ShipDate, "Delayed") syntax. Note that either method is dog slow
when you group on it.

Michael


Aaron [SQL Server MVP]

3/29/2007 1:32:00 PM

0

Yes, it's called a CASE expression. However, be aware that each possible
outcome must be in a compatible data type.

SELECT CASE WHEN ShippingStatus = 9 THEN CONVERT(CHAR(10), ShipDate, 120)
ELSE 'Delayed' END
FROM ...;

--
Aaron Bertrand
SQL Server MVP
http://www.sq...
http://www.aspfa...





<lesleyann76@gmail.com> wrote in message
news:1175174618.262103.43070@r56g2000hsd.googlegroups.com...
> In Sql, is there the equivalent of an "if" conditional statement? For
> instance, in Access I might use IIf([ShippingStatus] = 9, [ShipDate],
> "Delayed"). IIf(Condition, True, False).
>


lesleyann76

3/30/2007 1:51:00 AM

0

Great!
I have mostly done programming in Vba and now am moving toward sql
queries. Do you recommend a good reference where I could find an
extensive list of sql expressions?
Thank you,
Lesley.




Uri Dimant wrote:
> Hi
>
> Its called CASE expression, for more details see BOL
>
> BTW , there is IF cond. statement in SQL Server also:-))
>
>
> <lesleyann76@gmail.com> wrote in message
> news:1175174618.262103.43070@r56g2000hsd.googlegroups.com...
> > In Sql, is there the equivalent of an "if" conditional statement? For
> > instance, in Access I might use IIf([ShippingStatus] = 9, [ShipDate],
> > "Delayed"). IIf(Condition, True, False).
> >