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.
| Author |
Topic |
|
asumal_123
Starting Member
1 Post |
Posted - 2009-01-01 : 05:54:12
|
| Hi Friends, This is Sandeep. I have a problem that i am facing in my job that needs to be solved as soon as possible. I want to create a stored procedure that can accept a table name,its fields & corresponding field's values to insert/update in the same table at run-time from c# application (front-end). Plz send me the code or the method how to do that? |
|
|
Thiyagu_04
Starting Member
37 Posts |
Posted - 2009-01-01 : 07:28:53
|
| CREATE procedure InsertVal( @Tablename varchar(1000), @Fields varchar(max), @Values Varchar(max))asDECLARE @SQL Varchar(Max)SET @SQL ='Insert into '+@Tablename +'('+@Fields +')VALUES('+@Values+')'EXEC (@SQL)GOcall the procedure from the frontend.exec InsertVal 'customer','CustomerID,Name','105,''Test''' |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-01 : 11:37:46
|
quote: Originally posted by Thiyagu_04 CREATE procedure InsertVal( @Tablename varchar(1000), @Fields varchar(max), @Values Varchar(max))asDECLARE @SQL Varchar(Max)SET @SQL ='Insert into '+@Tablename +'('+@Fields +')VALUES('+@Values+')'EXEC (@SQL)GOcall the procedure from the frontend.exec InsertVal 'customer','CustomerID,Name','105,''Test'''
This is bad idea to create tables dynamically. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-01 : 13:14:41
|
| can you tell why you want to pass table name also as a variable? |
 |
|
|
|
|
|
|
|