Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Is It Possible

Author  Topic 

muvvasiva
Starting Member

14 Posts

Posted - 2009-06-01 : 07:37:35
Hi All,

I need to write a stored procedure with the following functionality.

-->To insert data into any table(all tables are in same schema) i use only this procedure
-->But this procedure should contain only one insert statement

I pass table name and values as input parameters

Actually i don't know ,it's possible or not

pls help me

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 07:41:15
yes. Possible with Dynamic SQL
read http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-01 : 07:50:36
Only ONE procedure for inserting into any table?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

muvvasiva
Starting Member

14 Posts

Posted - 2009-06-01 : 07:56:24
yes ,only one procedure

And Procedure also should contain only one insert statement

Go to Top of Page

muvvasiva
Starting Member

14 Posts

Posted - 2009-06-01 : 08:07:14
SET @query ='INSERT INTO '+@tableName+'('+substring(@string,0,len(@string)) + ') VALUES('
+ CONVERT(NVARCHAR(255),@j)+','+@k+','+@l+')'


there are two parts in the above insert statement
upto values(' it is ok.
but the problam is to convert the data types variables dynamically

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-06-01 : 08:45:24
Why on earth would you want to do this?
Go to Top of Page
   

- Advertisement -