If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Conditional statement in SQL Server query

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-09, 12:30
NotaDBGuru NotaDBGuru is offline
Registered User
 
Join Date: Aug 2009
Posts: 11
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...
Reply With Quote
  #2 (permalink)  
Old 10-29-09, 13:27
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 582
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
Wim

Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Reply With Quote
  #3 (permalink)  
Old 10-29-09, 14:07
NotaDBGuru NotaDBGuru is offline
Registered User
 
Join Date: Aug 2009
Posts: 11
Thanks a lot!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On