ms sql server if else语句可不可以用 switch 语句代替?
如下,存储过程可不可以改为 Switch 结构的存储过程,还有 if-else语句和 switch 语句那个效率较高。
ALTER PROCEDURE dbo.sp_getStatisticInfo
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
@ID char(3),
@StartTime varchar(20),
@EndTime varchar(20)
AS
if(@ID='1')
begin
select * from tb_dailyCheck where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='2')
begin
select * from tb_shiftCheck where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='3')
begin
select * from tb_weeklyM where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='4')
begin
select * from tb_doubleWeeklyM where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='5')
begin
select * from tb_monthlyM where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='6')
begin
select * from tb_quarterlyM where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
else if(@ID='7')
begin
select * from tb_quarterlyC where f_startTime between @StartTime and dateadd(day,1,@EndTime)
end
RETURN