select from a table

  • 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.

  • 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

  • Follow Pau;s advice. This is not possible directly except with dynamic sql.

    Steve Jones

  • Hi, I had the same "problem" and I did this:




    DECLARE @strSqlvarchar

    DECLARE @tablevarchar

    Set @table = 'TableName' + @name

    Select @strSql = "select * from ' + @table

    Exec (@strSql)

    I hope I help 😀

    Have a great weekend



Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply