November 26, 2008 at 2:44 pm
Hello,
I am trying to pass a table name as a parameter in a Stored Proc. But it returns the following error message.
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@TableOutput".
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@TableInput".
-- Below is the Stored Proc
alter proc InsertRecords
(
@TableInput varchar(50),
@TableOutput varchar(50),
@EmployeeIDStart int,
@EmployeeIDEnd int
)
as
declare @sql nvarchar(2000)
set@sql = 'insert @TableOutput (EmployeeID, FirstName, LastName, JobTitle) '
set@sql = @sql + 'select EmployeeID, FirstName, LastName, JobTitle '
set@sql = @sql + 'from @TableInput '
set@sql = @sql + 'where EmployeeID between @EmployeeIDStart and @EmployeeIDEnd'
exec (@sql)
-- The code I have used to execute the above Stored Proc InsertRecords is below.
exec InsertRecords 'HumanResources.vEmployeeNames',
'HumanResources.vEmployeeTableStructure',
1, 100
November 26, 2008 at 4:05 pm
Please don't cross post. It just wastes people's time and fragments replies.
Besides, I've already answered your post over here: http://www.sqlservercentral.com/Forums/Topic609456-147-1.aspx
No more replies to this thread please.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply