Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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

3873 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  
 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.03 seconds. Powered By: Snitz Forums 2000