SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 syntax help with IF
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lcsgeek
Starting Member

USA
38 Posts

Posted - 02/08/2013 :  12:39:47  Show Profile  Reply with Quote
Can someone help me with this syntax? Thanks much


SELECT
    column1
  , column2
  , IF @Subject = 'Mathematics' OR @Subject = 'Reading'
	BEGIN
	'Applicable Value'
	END
    ELSE
	BEGIN
	'N/A'
	END
   AS brSpringTarget
FROM ...

I want to check the value of the @Subject paramter and act accordingly.

James K
Flowing Fount of Yak Knowledge

3760 Posts

Posted - 02/08/2013 :  12:45:42  Show Profile  Reply with Quote
Use a case expression instead of the IF clause. IF is a control flow construct, which cannot be used in this context
SELECT
    column1
  , column2
  , CASE
		WHEN @Subject = 'Mathematics' OR @Subject = 'Reading' THEN 'Applicable Value'
		ELSE 'N/A'
	END brSpringTarget
FROM ...
Go to Top of Page

lcsgeek
Starting Member

USA
38 Posts

Posted - 02/08/2013 :  12:59:25  Show Profile  Reply with Quote
Thank you James
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3760 Posts

Posted - 02/08/2013 :  12:59:47  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000