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
 General SQL Server Forums
 New to SQL Server Programming
 Dynamic Query

Author  Topic 

yaman
Posting Yak Master

213 Posts

Posted - 2008-07-31 : 02:56:24
Sir

I have a dynamic query and i want to store a data which is come from dynamic query into another variable .
It is possible

set @col2=N'(SELECT '+@columnName+' FROM tbl_RTIDesignation WHERE '+@columnName+'=@desigName)';

if query execute some query return 'DESIGNATION NAME'
and i want to store a that name into another variable
Sir how can i


Yaman

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-31 : 03:09:42
read this 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 - 2008-07-31 : 05:18:57
quote:
Originally posted by yaman

Sir

I have a dynamic query and i want to store a data which is come from dynamic query into another variable .
It is possible

set @col2=N'(SELECT '+@columnName+' FROM tbl_RTIDesignation WHERE '+@columnName+'=@desigName)';

if query execute some query return 'DESIGNATION NAME'
and i want to store a that name into another variable
Sir how can i


Yaman


i think you need to use sp_executesql here. have a look at syntax and usage in books online.
Go to Top of Page
   

- Advertisement -