declare tablename

accessman2

Registered User.
Local time
Today, 06:24
Joined
Sep 15, 2005
Messages
335
declare @tbl as varchar(100)

-- setup the temporary table
@tbl = '## New Orders'

select Students, Sum(Orders) into @tbl
from members
where id = 1
or id = 2
Group By Students

when I run it, it has an error. @tbl is invalid in the statement.

What's wrong with it?

Thanks.
 
Hi there,

its a restriction of t-sql I'm afraid you cannot use a parameter as the value for your 'from' clause.

You have to do it this way...


SET @strSQL = ' SELECT ' + @myColumn + ' FROM ' + @myTable
EXEC (@strSQL)
 

Users who are viewing this thread

Back
Top Bottom