A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
The Software Craftsman
this week in the
JDBC and Relational Databases
Create procedure for inserting record into table : Table name dynamically as an Param
Joined: Dec 12, 2006
Nov 24, 2008 05:53:00
Hi I am trying to create a procedure which will insert record in to one table but for inserting record i need to specify table name dynamically which will come as input parameter to my procedure.
i have written the following procedure for the same
ALTER PROC insert_all( @tableName VARCHAR(100), @codeVARCHAR(50), @descVARCHAR(50) ) AS SET @tableName = 'mo_module' INSERT INTO @tableName (mo_code,mo_desc) VALUES(@code,@desc)
Error Stack Trace
Server: Msg 137, Level 15, State 2, Procedure insert_all, Line 8 Must declare the variable '@tableName'.
Can anybody help me out with this. thats the issue. i am declaring the tableName variable but its still showing the error.
I am using MS SQL Server 2000.
Thanks & Regards,
Joined: Oct 11, 2000
Nov 24, 2008 07:30:00
You cannot use a parameter in place of a table name.
You must replace the parameter with the actual table name before you send the INSERT statement to the database.
Perhaps consider using class "java.text.MessageFormat"?
Joined: Apr 14, 2004
Nov 24, 2008 07:47:00
You don't have access to
in Transact-SQL. See your
for a way of doing this.
Have you tried LearnNowOnline?
subject: Create procedure for inserting record into table : Table name dynamically as an Param
WITHOUT STORED PROCEDUREs
procedure return resultset
Stored Procedure problem
INSERT INTO SELECT FROM
How would I do a all-round searching for all tables of the database?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015