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
 Exec Buffer

Author  Topic 

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-01 : 06:43:39
create table #a (id int)
insert into #a values (1)
Declare @a varchar(25),@b nvarchar(25) ,@C nvarchar (25)
set @C='id'
set @a='Select '+@C+' from #a'
exec(@a)


How to store this @a result in other variable @b I dont need to create temp table

Raghu' S

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-01 : 08:20:02
Ok friends I got solution for this

create table #t
(id int)
insert into #t values(1)


declare @j varchar(5),@v int
set @j='id'
declare @t table (col varchar(5))
insert into @t exec ('select '+ @j +' from #t')
select @v=col from @t
select @v


Raghu' S
Go to Top of Page
   

- Advertisement -