Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Case Statement to select which database to use within a Routine

Status
Not open for further replies.

CruzN

Technical User
Jul 8, 2009
3
US
Hello,

I am trying to eliminate the need for creating multiple Routines which are doing the same thing on different databases.

I would like to use the "USE DB1;" syntax at the beginning of a routine to determine which database to look at. Each database has the same structure (Tables/Views) are identical. However the data stored within the tables are different.

Is it possible to use a CASE statement to determine which database to look at?
i.e.

Case
when Client = XXX then USE db1
when Client = YYY then USE db2
when Client = ZZZ then USE db3
Else USE db4
END

After the database to use is identified, it will run the routine against that DB and retrieve the results respectively.

Is this possible?

Thanks,
Charlie (MySQL Rookie)
 
I have to agree with Rudy, that type of logic should be occurring before you connect to he database.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top