Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2011
    Posts
    78

    Unanswered: How do I put in if conditions in the SQL Statements?

    For the VSTATUS, I want to make it like:

    If 'A'=Invoice

    If 'F'= No Invoice


    How do I go about implementing a If condition in the statement?
    Please help, thank you.




    select

    [I_DETAIL].[VSTATUS]

    FROM [Opt].[EDA4010].[IDETAIL] as invoice_detail

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Although it won't help mangolili, I just want to mention that SQL Server Denali CTP3 has got IIF
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  4. #4
    Join Date
    Jul 2011
    Posts
    78
    Thank you so much for the link. I tried to write it like this (highlighted part), but I got syntax errors.

    Please help, thank you.


    select
    [I_DETAIL].[CASTMONTH]
    ,[I_DETAIL].[VSTATUS]=
    case
    when 'Aired' then 'Invoice'
    when 'Failed' then 'No Invoice'
    else 'Not Applicable'
    end

    ,[I_DETAIL].[SLENGTH]
    ,CONVERT (VARCHAR(10),[INVOICE_DETAIL].[ATIMEDATE], 111) as ADATE
    ,CONVERT(VARCHAR(10),[INVOICE_DETAIL].[ATIMEDATE], 8) as ATIME


    FROM [Opti].[EDA4010].[I_DETAIL] as i_detail

  5. #5
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Code:
    ,case [I_DETAIL].[VSTATUS]
    when 'Aired' then 'Invoice'
    when 'Failed' then 'No Invoice'
    else 'Not Applicable'
    end as VSTATUS
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  6. #6
    Join Date
    Jul 2011
    Posts
    78
    Thank you so much for the syntax correction. It works now =)

Posting Permissions

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