Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parameterized sql stored proc.
Message
 
 
To
06/12/2002 14:55:45
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00730459
Message ID:
00730466
Views:
17
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--
Previous
Reply
Map
View

Click here to load this message in the networking platform