•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 373,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,724 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 703 | Replies: 1 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
can anyone tell me how to use a variable table name in select syntax??
like..select * from tablename
here tablename is a variable name ..i read tht it can be done using dynamic sql..but i am not able to do it..can anyone tell me the code for it...i tried writin a procedure like this..
is this right?? or am i doin any syntax or semantic error??
like..select * from tablename
here tablename is a variable name ..i read tht it can be done using dynamic sql..but i am not able to do it..can anyone tell me the code for it...i tried writin a procedure like this..
sql Syntax (Toggle Plain Text)
CREATE procedure vartable(tablename varchar(255) begin declare varsql varchar(4000); varsql='select * from tablename'; exec(varsql); end;
is this right?? or am i doin any syntax or semantic error??
Last edited by peter_budo : Apr 17th, 2008 at 3:12 pm. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Dec 2007
Posts: 102
Reputation:
Rep Power: 1
Solved Threads: 12
SQL Syntax (Toggle Plain Text)
SET @a = 'table'; SET @x := CONCAT('SELECT * FROM ', CONCAT(@a, '_', 'name')); Prepare stmt FROM @x; Execute stmt;
SQL Syntax (Toggle Plain Text)
SELECT * FROM table_name;
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
- Previous Thread: help for log files
- Next Thread: key problem


Linear Mode