Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    11

    Unanswered: Conditional statement in SQL Server query

    I have never written a formula in a SQL Server query before, just in Access and Oracle...

    I have an "iif" satement that works great in access and I am attempting to move it to SQL Server. I have learned in these forums to use "Case" instead of "IIF" Now I am stuck.

    I am running into errors when I run the following in my query:

    CASE WHEN (RIGHT(dbo.[000 Financial Reporting Map].[Mdse Sales], 5) = 'Sales' THEN dbo.GL_Account_Balances_All.[PTD Amt] * - 1 ELSE '0' END)
    AS Sales_Dollars

    The errors are: incorrect syntax near the word THEN

    Any help would be greatly appreciated...

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Code:
    CASE WHEN (RIGHT(dbo.[000 Financial Reporting Map].[Mdse Sales], 5)) = 'Sales' 
              THEN dbo.GL_Account_Balances_All.[PTD Amt] * - 1
              ELSE '0' 
    END
    AS Sales_Dollars
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Aug 2009
    Posts
    11
    Thanks a lot!

Posting Permissions

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