December 11, 2001 at 8:28 pm
How I can use a variable to be a table name in select from sentence. for example:
select * from @table_name. This way doesn't work. Can some one help me. Thank you.
December 12, 2001 at 2:26 am
Have a look at Page 2 of this forum - there is a relevant thread ("Select * from @var" possible?") which will probably answer your questions.
Paul Ibison
Paul Ibison
Paul.Ibison@replicationanswers.com
December 12, 2001 at 10:13 am
Follow Pau;s advice. This is not possible directly except with dynamic sql.
Steve Jones
December 14, 2001 at 11:42 am
Hi, I had the same "problem" and I did this:
CREATE PROCEDURE spExample
@namevarchar
AS
DECLARE @strSqlvarchar
DECLARE @tablevarchar
Set @table = 'TableName' + @name
Select @strSql = "select * from ' + @table
Exec (@strSql)
I hope I help 😀
Have a great weekend
Ana
Ana
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply