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.
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 beginset @CandidateBCS = @CandidateBCS + 6endif @EPTChironomidaePercentage >=50 and @EPTChironomidaePercentage <=75 beginset @CandidateBCS = @CandidateBCS + 4endif @EPTChironomidaePercentage >=25 and @EPTChironomidaePercentage <=50 beginset @CandidateBCS = @CandidateBCS + 2endif @EPTChironomidaePercentage <25 beginset @CandidateBCS = @CandidateBCS + 0end |
|
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 0end[/code] |
|
|
|
|
|