You've to build sql string and than execute it dynamicaly.
CREATE PROCEDURE MYPROC
@MYTABLE_NAME VARCHAR(50),
@MYVALUE VARCHAR(10)
AS
DECLARE @sqlstring nvarchar(512)
SET @sqlstring = 'DELETE FROM ' + @MYTABLE_NAME +
'WHERE TABLE_FIELD = ''' + @MYVALUE + ''''
EXECUTE (@sqlstring)
You can use sp_executesql instead of EXECUTE and pass @MYVALUE as parameter instead of building it into Sql string.
>I'm trying this on SQL SERVER 7.0
>
>CREATE PROCEDURE MYPROC
>@MYTABLE_NAME VARCHAR(50),
>@MYVALUE VARCHAR(10)
>AS DELETE FROM @MYTABLE_NAME WHERE TABLE_FIELD = @MYVALUE
>
>My intention is to create a stored procedure wich I can use to delete records from different tables depending on a parameter; but it seems that SQL does not accept a parameter as a valid expression for a table name.
>
>SQL responds with an error message in line 3 saying: Error near @MYtable_name
>
>Is there any way to get what I want?
>
>TIA
--sb--