Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can I pass a Table name aa column name as variables into a stored procedure, that would then do an SQL statement :
Update tableName set columnName='' ; ?
Posted

1 solution

Yes you can. Using Exec sql query in a Stored Procedure.

1. Create a stored procedure
2. Keep an input parameter to it as "@TableName" & "@ColumnName"
3. Create a dynamic sql statement inside your SP
4. Create a parameter named "@dynamicSQL" as a string.
5. Set @dynamicSQL = 'Select '+@ColumnName+' from '+@TableName.
6. Now execute the dynamic sql: Exec @dynamicSQL

Try!
 
Share this answer
 
Comments
KaRaMiLo 9-May-11 11:16am    
i can't apply it on update statements
Sandeep Mewara 9-May-11 11:18am    
Why not? Same theory applies for update or insert. You need to use SP though - which should not be an issue.
KaRaMiLo 9-May-11 11:23am    
i keep getting this error :
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Sandeep Mewara 9-May-11 11:30am    
Try & in place of +

For such things, you should always run the raw query first and check if it is working fine and returing result. If you still face issues, first fix the query and then try to code for it as suggested.
KaRaMiLo 9-May-11 11:37am    
still not working and when i compile it nothing is wrong but when i run it that message keep coming

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900