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 2005 Forums
 Transact-SQL (2005)
 easier way to do this

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2008-12-19 : 11:56:29
hi all,

i got a SP with input parameters that updates few records:
SP_update
@domain as varchar(50)
@bool1 as bit,
@bool2 as bit,
@bool3 as bit
@bool4 as bit

AS
update T_WSEC_Config
set config=@bool1
where sitename=@domain and label='bool1'

update T_WSEC_Config
set config=@bool2
where sitename=@domain and label='bool2'

update T_WSEC_Config
set config=@bool3
where sitename=@domain and label='bool3'

update T_WSEC_Config
set config=@bool4
where sitename=@domain and label='bool4'


there a lot more parameters then this.
my question is, is there a beter more efficient way to do this?

thanks a lot

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-19 : 12:20:15
Use a CASE statement.

set config = CASE WHEN label = 'bool1' THEN @bool1 WHEN label = 'bool2' THEN @bool2 WHEN ... END

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2008-12-19 : 12:30:33
That is a lot better, Thanks a lot!

quote:
Originally posted by tkizer

Use a CASE statement.

set config = CASE WHEN label = 'bool1' THEN @bool1 WHEN label = = 'bool2' THEN @bool2 WHEN ... END

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-19 : 12:32:04
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -