Results 1 to 3 of 3

Thread: SQL server and SQL

  1. #1

    Thread Starter
    New Member
    Join Date
    May 1999
    Location
    South Africa
    Posts
    3

    Post

    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



  2. #2
    New Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    6

    Post

    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

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width