Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How create Dynamic Stored Procedure?

Status
Not open for further replies.

bharanikrishna

Programmer
Jun 1, 2001
3
IN
i want one stored procedure

specs: i give three parameters to the stored procedure , using these three parameters the stored procedure will insert data into database

parameters


param1: tablename
param2: column name
param3: column data(some value to that column)

so write a sql stored procedure it genates dynamic
sql query. after genarating sql query we have to execute that query in the same stored procedure..

Thanking you
Bharani krishna
 

Only one column to update in the table? No data types in the spec? Not much to go on! Oh well, here goes...

------------------------------
Create Procedure DynamicProc
@tblname varchar(128),
@colname varchar(128),
@data varchar(128) As

Declare @sql varchar(1024)

Set @sql="Insert " + @tblname + "(" + @colname + ") Values('" + @data + "')"

exec sp_executesql @sql

Go

------------------------------

Task accomplished! Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top