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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with CASE statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

thebrenda
Starting Member

22 Posts

Posted - 09/04/2013 :  11:38:57  Show Profile  Reply with Quote
I have a @Period parameter that can equal 'Monthly', 'Quarterly', or 'Yearly'. Looking for a way to use the CASE statement to get the desired results. Thanks.

If it is 'Monthly' want to
UPDATE ifs_PPBatchControl_Work
SET [Backup Flag] = 1
WHERE [Database Frequency] in ('MONTHLY')

If it is 'Quarterly' want to
UPDATE ifs_PPBatchControl_Work
SET [Backup Flag] = 1
WHERE [Database Frequency] in ('MONTHLY', 'QUARTERLY')

If it is 'Yearly' want to
UPDATE ifs_PPBatchControl_Work
SET [Backup Flag] = 1
WHERE [Database Frequency] in ('MONTHLY', 'QUARTERLY', 'YEARLY')

James K
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 09/04/2013 :  11:56:13  Show Profile  Reply with Quote
One way to have the same logic would be this:
UPDATE ifs_PPBatchControl_Work
SET [Backup Flag] = 1 
WHERE 
	([Database Frequency] = 'MONTHLY' AND @Period = 'MONTHLY' )
	OR
	([Database Frequency] IN ('MONTHLY','QUARTERLY') AND @Period = 'QUARTERLY' )
	OR 
	([Database Frequency] IN ('MONTHLY','QUARTERLY', 'YEARLY') AND @Period = 'YEARLY' )
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.05 seconds. Powered By: Snitz Forums 2000