472,146 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 1070

"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
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.