markSaunders
Programmer
Is is possible to have a stored proc that will run against a table that is specified as a parameter - such as....
where Item represents the table
This would allow me to use one stored procedure against 5 almost identical tables rather than 5 stored procs.
The error message I receive is
as it's obviously trying to execute a stored proc and not the actual command line I have defined.
Any ideas?
mark Mark Saunders
Code:
CREATE PROCEDURE usp_items @iItem INT=0,
@vItem varchar(50)
AS
DECLARE @string varchar(255)
SET @string = 'SELECT * FROM ' + @vItem + ' WHERE (' + @vItem + 'ID=' + cast(@iItem as varchar) + ') or (@i' + @vItem + '=0) ORDER BY title'
execute @string
GO
where Item represents the table
This would allow me to use one stored procedure against 5 almost identical tables rather than 5 stored procs.
The error message I receive is
Code:
Server: Msg 2812, Level 16, State 62, Line 17
Could not find stored procedure 'SELECT * FROM skill WHERE (skillID=0) or (@iskill=0) ORDER BY title'.
as it's obviously trying to execute a stored proc and not the actual command line I have defined.
Any ideas?
mark Mark Saunders