samedi 28 février 2015

SELECT FROM @random_table SQL-SERVER 2008 R2

I'm having an issue with the following code:



DECLARE @table varchar(50), @value int
SET @table = 'randomTable'
EXEC('SELECT @value = exercicio FROM '+@table+' WHERE cod=2')


I need to do a couple of operations like that one above in some random tables. I want to select a value and store in a variable preveiously declared. But when I tried to execute that code, I received the following message:



Must declare the scalar variable "@value".


I'm out of ideas. Any suggestions?





Aucun commentaire:

Enregistrer un commentaire