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 2000 Forums
 Transact-SQL (2000)
 Using CASE in place of IF THEN

Author  Topic 

RussB17
Starting Member

4 Posts

Posted - 2008-09-29 : 10:16:01
I have the following IF THEN code in a stored procedure. It works fine but I'm wanting to know if this would be better written T-SQL code if I could use the CASE statement. I haved tried several CASE code scriptings but with no luck. Can anyone construct a CASE statement to replace the IF THEN code for testing a variable to four different ranges?
Thanks for any replies I may receive.
R.

if @EPTChironomidaePercentage > 75 begin
set @CandidateBCS = @CandidateBCS + 6
end

if @EPTChironomidaePercentage >=50 and @EPTChironomidaePercentage <=75 begin
set @CandidateBCS = @CandidateBCS + 4
end

if @EPTChironomidaePercentage >=25 and @EPTChironomidaePercentage <=50 begin
set @CandidateBCS = @CandidateBCS + 2
end

if @EPTChironomidaePercentage <25 begin
set @CandidateBCS = @CandidateBCS + 0
end

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 10:19:33
[code]set @CandidateBCS = @CandidateBCS +
case when @EPTChironomidaePercentage > 75 then 6
when @EPTChironomidaePercentage >=50 and @EPTChironomidaePercentage <=75 then 4
when @EPTChironomidaePercentage >=25 and @EPTChironomidaePercentage <=50 then 2
when @EPTChironomidaePercentage <25 then 0
end[/code]
Go to Top of Page
   

- Advertisement -