473,486 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

variable table/field names in stored procedures

2 New Member
Hi All !

is it possible to use variable table and/or field names in stored procedures i.e. construct the name of a table/field based on an input parameter as in :

Expand|Select|Wrap|Line Numbers
  1. create procedure toto(in p_name char(5), out p_count int)
  2. begin
  3. select count(*) into p_count from table_'p_name'
  4. end
  5.  
where the table name from which I am selecting is the concatenation of the prefix 'table_' and the value of the input parameter p_name.

Cheers,

M.
Nov 13 '06 #1
3 10070
zeno
2 New Member
Hi All !

I answered my own question. To do so, construct your SQL statement dynamically with the CONCAT() function and then PREPARE and EXECUTE your query with it.

HTH,

Martin.
Nov 15 '06 #2
rebeccam
1 New Member
Hello! I am having a similar problem, but with the name of the database. Could you please share more information about how to use the CONCAT() function and then PREPARE and EXECUTE? Thanks!

rebeccam


Hi All !

I answered my own question. To do so, construct your SQL statement dynamically with the CONCAT() function and then PREPARE and EXECUTE your query with it.

HTH,

Martin.
Nov 27 '06 #3
gwk
1 New Member
HI here's how it works

CREATE TABLE `tab` (
`mycol` INTEGER UNSIGNED NOT NULL DEFAULT NULL AUTO_INCREMENT,
PRIMARY KEY (`mycol`)
)ENGINE = InnoDB;

SET @A = "mycol";
SET @B = CONCAT("SELECT ",@a," FROM tab;");
PREPARE stmt1 FROM @b;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
Feb 5 '07 #4

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

Similar topics

4
12065
by: Greg | last post by:
I need to send the result of a procedure to an update statement. Basically updating the column of one table with the result of a query in a stored procedure. It only returns one value, if it didnt...
17
2175
by: serge | last post by:
How can i delete all user stored procedures and all table triggers very fast in a single database? Thank you
6
4812
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
6
4295
by: shaan.shaan | last post by:
Hi I am trying to set an env. variable by exporting in unix environment on DB2. I am using export var_name=ON, but it is not taking the value of the var_name. This thing is working fine when I...
1
3327
by: jobs | last post by:
I have a growning list of stored procedures that accept a single string as a parameter. The list and parameters are maintained in a table with two columns. Some of the Stored procedures take...
4
1912
by: sparks | last post by:
We have a new project here, one that I have never tried maybe its easy I don't know yet. We have people that have records dating back over 5 yrs on a sql server. We have to build an access 2003...
12
4593
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT) ...
14
4567
by: jehugaleahsa | last post by:
Hello: I am working with Oracle .NET Stored Procedures. I would like to know how to return the results of a SELECT statement. I have tried returning a OracleRefCursor and a DataTable, but...
2
1401
by: courbiff | last post by:
Hi everybody I'm wrinting a stored procedure in order to use this last one in a migration script. During the writing i've notice that i have to use a variable in a cursor .. For example ...
0
7099
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,...
0
7123
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,...
1
6842
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...
0
4559
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...
0
3069
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.