Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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_WorkSET [Backup Flag] = 1WHERE [Database Frequency] in ('MONTHLY')If it is 'Quarterly' want to UPDATE ifs_PPBatchControl_WorkSET [Backup Flag] = 1WHERE [Database Frequency] in ('MONTHLY', 'QUARTERLY')If it is 'Yearly' want to UPDATE ifs_PPBatchControl_WorkSET [Backup Flag] = 1WHERE [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_WorkSET [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' )