August 13, 2007 at 10:37 pm
Hello,
I am trying to make a query like this :
SELECT field
FROM @tablename <---||
WHERE ...
In any way I have an error
[@tablename]
'@tablename'
"@tablename"
Sql server does not recognize the object name.
Thank you
Bye Pier
August 13, 2007 at 10:45 pm
The object of the FROM clause may not be a variable. You'll need to use dynamic SQL to do this.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 15, 2007 at 12:07 am
declare @TableName as varchar(100)
declare @cmd as varchar(8000)
set @cmd = 'select * from ' + @TableName + ' where ...'
exec (@cmd)
thank you
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply