473,666 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable for table name in stored procedure

8 New Member
hi all;
i am using a db2 database on RAD platform and need to generate tables (names of them will be determined by users.) so i thought i can do this with a stored procedure which takes the table name as input. but i live difficulty with usimg the table name ..

create procdure proc1 (IN inName VARCHAR(30))
BEGIN
Create TAble inName(this is table name variable) (and the rest of the table definition..)
END

the code snippet above did not work then i tried to use the input variable after @ character but it did not work also..

any suggestions to achieve this?

thank you all.. :)
Mar 7 '08 #1
1 6879
sakumar9
127 Recognized Expert New Member
You can try following code:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE  proc1 (IN inName VARCHAR(30))
  2. BEGIN
  3.     DECLARE param VARCHAR(1000);
  4.  
  5.         SET param = 'Create Table ' || inName || '(a INT)';
  6.  
  7.         PREPARE s1 FROM param;
  8.         EXECUTE s1;
  9.  
  10. END@
  11.  
  12.  

Regards
-- Sanjay
Mar 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4962
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if they are present, making the assumption the database will support the given feature. The problem is I can't find a certain stored procedure in the sysobjects table, even though I know it exists and can see other similar procedures using: select...
10
5616
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
0
1645
by: joe pribele | last post by:
I have this stored procedure that takes some xml as input. What I need to is use xml as a table so that I can join other tables to the xml and get information back that matches the criteria. I can use dxxshredxml to put it into a regular table and everything works great. but when I try to put it into a temp table it doesn't work. I get an error saying Session.ACCESSMASK doesn't have a column name ACCESS_MASK_ID. Do I have to use a...
1
3695
by: Lauren Quantrell | last post by:
I have read the newsgroups and see this is a common issue but I saw no resolution for it: I have an Access2K frotn end and SQL Server 2K backend. In access, I create a temp table using code in a module: strSQL = "CREATE TABLE #tempTableName ("TempID int NOT NULL IDENTITIY (1,1) PRIMARY KEY, Field1 int...) CurrentProject.Connection.Execute strSQL,,adCmdText so far so good...
6
26842
by: antmail | last post by:
Hi guys, I have spend several days now trying to solve this problem inside a stored procedure. I want to call a procedure providing 3 variables. The variables area used to select the appropriate table from within the database. I have to concatenate the 3 variables to make up the whole table name and concatenate that with the field name. The hard coded procedures looks as follows: DROP PROCEDURE IF EXISTS...
0
4701
by: amit | last post by:
The Table tt_local will be created when you execute the procedure. The table does not exist when you compile it. There are two options 1. Create the global temporary table manually Remove the creation of the table from the proc and then compile it. 2. Run the insert also as dynamic sql. Remember dynamic sqls don't go through semantic check at compile time.
3
2838
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be programmatically set, this is necessary because I may have a simple table name or a union, hence I got to pick the correct one! Unfortunately, I can't bind this parameter to a control, session or
9
3837
by: Slickuser | last post by:
Hi, I'm trying to use my variable in another variable. How can I achieve that? I can use + (concat) but it will be a lot me to concatenate. I have to use 3 variables with 15 replacement. Ex:
3
7733
by: dmorand | last post by:
I'm very new to stored procedures so this is probably something very dumb. I want to pass a name of a table to be created to my stored procedure. I'm using the variable @tableName in the code below but I'm getting an error: Server: Msg 170, Level 15, State 1, Procedure usp_CodeGreyData, Line 22 Line 22: Incorrect syntax near '@tableName'. Server: Msg 137, Level 15, State 1, Procedure usp_CodeGreyData, Line 29 Must declare the variable...
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.