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 2008 Forums
 Transact-SQL (2008)
 CASE in Select Statement

Author  Topic 

7siva7
Starting Member

28 Posts

Posted - 2011-11-24 : 03:22:22
DECLARE @TestVal int,@Val varchar(30)
SET @TestVal = 3

SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END


the above code prints "Third"

but i want to store it in another variable @Val

how can i store it

select @Val =(case.....) not working

please help me


HI

7siva7
Starting Member

28 Posts

Posted - 2011-11-24 : 03:24:41
Sorry ...Working fine //// :)

HI
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-24 : 06:15:49
Have you used this?

SELECT @val=
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -