Eng | Rus
 
Education -> Solutions -> SQLstored
 
 
 
Simple Seo Solutions
SEO and Promotion
sites
VoiceNotebook.com
Speech to text for AndroidAndroid speech to text

Pass table name as a parameter to sql server procedure

This example shows how to  make a query  to the table that name has been transferred to the stored procedure as a an argument.

CREATE PROCEDURE dbo.mysample
(
@tabname varchar(50),
@somevalue char(50)
)
AS
declare @sql varchar(400)

set @sql='DELETE FROM '+ @tabname + ' where somefield='+ CHAR(39) + @somevalue + CHAR(39)
exec(@sql)

As you can see, CHAR(39) represents symbol ' in the sql query.

This sql query deletes all records in the given sql server table if the value of the field "somefield" matches the @somevalue parameter.

© prjsoft.ru