Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 SELECT * FROM @variable?

It is possible?

DECLARE @vTableName varchar(50)

SET @vTableName = (SELECT TableName FROM qms_Types WHERE Id = 1)

SELECT * FROM @vTableName

I have this error:

Msg 1087, Level 16, State 1, Line 3 Must declare the table variable "@vTableName".

like image 687
soamazing Avatar asked Apr 05 '12 14:04

soamazing


1 Answers

my solution for this:

EXECUTE('SELECT * FROM  ' + TableName + '')
like image 69
Iago Correia Guimarães Avatar answered Jan 02 '23 01:01

Iago Correia Guimarães