June 22, 2009 at 11:18 am
My Stored Procedure Gets a value from front end.i,e. L0, L1,L2,L3
Depening on what value is send from the front end, i need to set the value for a variable. Can this be done using CASE statement?? I have used the IF-ELSE statement to perform this;
CREATE PROCEDURE usp_MyProcedure
(
@Type NVARHCHAR(2)
)
AS
BEGIN
DECLARE @Var INT
IF(@Type ='L0') @Var=0
ELSE IF (@Type ='L1') @Var=1
ELSE IF (@Type ='L2') @Var=2
ELSE IF (@Type ='L3') @Var=3
Can the same be achieve by CASE statement? Or the above holds good
June 22, 2009 at 12:50 pm
naveenreddy.84 (6/22/2009)
My Stored Procedure Gets a value from front end.i,e. L0, L1,L2,L3Depening on what value is send from the front end, i need to set the value for a variable. Can this be done using CASE statement?? I have used the IF-ELSE statement to perform this;
CREATE PROCEDURE usp_MyProcedure
(
@Type NVARHCHAR(2)
)
AS
BEGIN
DECLARE @Var INT
IF(@Type ='L0') @Var=0
ELSE IF (@Type ='L1') @Var=1
ELSE IF (@Type ='L2') @Var=2
ELSE IF (@Type ='L3') @Var=3
Can the same be achieve by CASE statement? Or the above holds good
I've got two different ways to handle what you're doing:
set @Var = case @Type
when 'L0' then 0
when 'L1' then 1
when 'L2' then 2
when 'L3' then 3
end
and:
set @Var = convert(int, substring(@type, 2, len(@Type)))
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 23, 2009 at 11:53 am
Thanks a lot!!!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply