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 2000 Forums
 Transact-SQL (2000)
 Dynamic SQL variable declaration

Author  Topic 

Scott
Posting Yak Master

145 Posts

Posted - 2004-10-12 : 07:45:21
I have some dynamic SQL:

Declare @Proc varchar(1000), @TheValue int
set @Proc = 'declare @Value int '
set @Proc = @Proc + 'Select @Value = somevalue from '+@SomeTablevariable '
exec(@Proc)
@TheValue = @Value

Does not work because @Value is not declared.
How can I assign @Value to @TheValue?

Thanks
Scott

hgorijal
Constraint Violating Yak Guru

277 Posts

Posted - 2004-10-12 : 08:12:37
try this....

Declare @Proc varchar(1000), @TheValue int
declare table #temp (somevalue int)
set @Proc = 'Insert into #temp Select @Value = somevalue from ' + @SomeTablevariable
exec(@Proc)
select @TheValue = somevalue from #temp



Hemanth Gorijala
BI Architect / DBA...
Go to Top of Page
   

- Advertisement -