PDA

Click to See Complete Forum and Search --> : SQL server and SQL


clyde
Aug 4th, 1999, 05:51 PM
Hi there

How can I use if in a sql statement for a MS SQL server.

Here is an example in and access database
SELECT iif([t.recMags] = "Blade","$500","%450"), t.recTyreMake, t.recValve
FROM tbltyres t;

The syntax might be wrong but it is the idea that counts ...

Thanks
Clyde

Tomo
Aug 5th, 1999, 06:35 PM
Clyde,

Why not use SELECT <FIELDS> FROM tbltyres WHERE RECMAGS IN("Blade", "$500", "%450"), or were you specifically wanting to use the iif statement in which case I am unable to help.

Thomas

JHausmann
Aug 6th, 1999, 01:04 AM
I've never used iif but it appears to return one value if a field test returns true and the other value if false.

The SQL equivalent might be (for the example given -"SELECT iif([t.recMags] = "Blade","$500","%450"), t.recTyreMake,t.recValve
FROM tbltyres t;" :

Select "$500", t.recTyreMake, t.recValve FROM tbltyres t where t.recMags= "Blade"
UNION ALL
Select "%450", t.recTyreMake, t.recValve FROM tbltyres t where t.recMags<> "Blade"


[This message has been edited by JHausmann (edited 08-06-1999).]