469,081 Members | 1,894 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

Variable in Variable

Is it possible to print the the value of a variable in a variable
what i mean:

Declare @test varchar(255)
Declare @foo varchar(255)
Declare @strSQL varchar(255)

set @test = 'Hallo'
Set @foo = '@test'

Print @foo
Set @strSQL = 'SELECT ' + @foo --Expected result is 'Hallo'
exec master..sp_ExecuteSQL @strSQL

How doess it work?
I hope you understand my problem
Thanks
Jul 20 '05 #1
1 1032

"Michi Albatross" <al***@netdot.ch> wrote in message
news:67**************************@posting.google.c om...
Is it possible to print the the value of a variable in a variable
what i mean:

Declare @test varchar(255)
Declare @foo varchar(255)
Declare @strSQL varchar(255)

set @test = 'Hallo'
Set @foo = '@test'

Print @foo
Set @strSQL = 'SELECT ' + @foo --Expected result is 'Hallo'
exec master..sp_ExecuteSQL @strSQL

How doess it work?
I hope you understand my problem
Thanks


I guess you're looking for something like this? See sp_executesql in BOL for
more details on the syntax.

Simon

Declare @test varchar(255)
Declare @foo varchar(255)
Declare @strSQL nvarchar(255)

set @test = 'Hallo'
Set @foo = @test

Print @foo
Set @strSQL = 'SELECT @foo'
exec sp_ExecuteSQL @strSQL, N'@foo varchar(255)', @foo = @test
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Frederik Sørensen | last post: by
134 posts views Thread by James A. Donald | last post: by
pbmods
1 post views Thread by pbmods | last post: by
112 posts views Thread by istillshine | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.