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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with CASE statement

Author  Topic 

thebrenda
Starting Member

22 Posts

Posted - 2013-09-04 : 11:38:57
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-04 : 11:56:13
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
   

- Advertisement -