Results 1 to 4 of 4

Thread: SQL sentence

  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Exclamation Unanswered: SQL sentence

    Hi, I need to make a query that, according to the value of a field, returns an specified value.

    ie:
    TABLE:
    Col1
    1
    0

    I need to make a query like:
    SELECT (????) FROM TABLE

    and if Col1=1 returns 'Assigned' and if Col2=0 it returns 'Unassigned'

    So the result from the query for the data above is:
    Assigned
    Unassigned

    Thankx

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    select case col1 when 1 then "Assigned" when 0 then "UnAssigned" from table
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Select
    CASE column
    WHEN 0 THEN 'Unassigned'
    WHEN 1 THEN 'Assigned'
    ELSE 'N/A'
    END
    from table
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  4. #4
    Join Date
    Jul 2003
    Location
    England
    Posts
    152
    Have a look at the CASE statement in BOL - that should resolve your issue. It is better explained there, than I can do here, and its got some good examples.
    Regards
    Dbabren

Posting Permissions

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