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 2005 Forums
 Transact-SQL (2005)
 T-sql code

Author  Topic 

goodsolution
Starting Member

38 Posts

Posted - 2009-10-08 : 23:27:45
Hi all,
I have a little doubt on writing sql statement using a variable,

Ex:
declare @i
set @i = '(case when q.id = 123 then 2 else q.id) '

-- I am not expecting the below result
select @i as id from question
Getting Result :
id
(case when q.id = 123 then 20000 else q.id)


-- I am expecting the below result
Expected Result :
id
20000


How can i use the variable to achieve the Expected Result?

Thanks.


-Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-08 : 23:31:07
via dynamic SQL. see http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-09 : 13:44:09
not sure why you need to pass the case expression via dynamic sql. are you trying for cross tabbing the result?
Go to Top of Page
   

- Advertisement -