Using variable for DBname in SELECT statement, within stored procedure
Posted on 2006-05-18
I'm using DB2 v5r2 on iSeries AS/400.
Is it possible to use a variable as the database name in a select statement ?
For example something that would look like:
DECLARE v_total INT DEFAULT 0;
DECLARE v_mydb VARCVHAR(10) DEFAULT '';
SET v_mydb = 'DBNAME';
The reason for this is that I have 10+ databases identical from a structure standpoint, but different data. And based on a parameter to the stored procedure, I need to point to a different database, and I'd hate to have to use CASE / WHEN, and have to replicate the code inside each case statement...