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)
 Something Similar to Switch for SQL?

Author  Topic 

CVDpr
Starting Member

41 Posts

Posted - 2008-11-20 : 10:01:39
Hey there i do a select depending of what they want, i use a couple of If. Is there something similar to switch for sql of a better approach to do this?


create procedure sp_sel_MstAHBTE_Sel

@what as varchar(20)
as
begin
set nocount on

if @what = 'fcid'
select FCID, Description from MstFinancialClass with(nolock)
if @what = 'servicearea'
select ServiceArea, Description from MstServiceArea with(nolock)
if @what = 'regtype'
select RegistrationType, Description from MstRegistrationType with(nolock)
if @what = 'billtype'
select BillTypeID, Description from MstBillType with(nolock)
if @what = 'patienttype'
select PTID, Description from MstPatienttype with(nolock)
end

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-20 : 10:02:47
no, that's pretty much it.


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-11-20 : 11:34:08
why not call 5 different SP's...each one doing one job?
you may have some chance then of getting a decent execution plan (for each one)
Go to Top of Page

thiyagu_rind
Starting Member

46 Posts

Posted - 2009-01-08 : 01:13:03
Hi Dear,

Why cant you use the CASE instead of the IF Condition. Also form a dynamic query in a string and execute at the end of the procedure.

I hope it will be more better.


Regards
Thiyagarajan
www.sqlhunt.blogspot.com
Go to Top of Page
   

- Advertisement -