conversion of one data type to another

  • I am writing a store procedure in which i have a variable of "NVARCHAR" type. In this variable, I have stored a string of a table name. That table exists in my database. Now i have to run a 'SELECT' query for getting results but the problem is that this variable is "NVARCHAR" type while to get results from 'SELECT' query it should be "TABLE" data type. IS there is any solution to convert "NVARCHAR" data type into "TABLE" data type or any other solution for this situation?

  • Firstly, this question should be posted in a different forum - like Newbie or Development!

    If I understand you correctly, what you want to do is to execute a sql statement dynamically, eg.

    declare @table_name varchar(255)

    declare @sql varchar(1000)

    set @table_name = 'dbo.Table01'

    set @sql = 'select col1, col2 from ' + @table_name

    EXEC (@sql)

Viewing 2 posts - 1 through 2 (of 2 total)

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