acsakany
asked on
SQL dynamic table names
I have a database with tables that are named with the following format
priceHistory200812
priceHistory200811
priceHistory200810 etc....
Based upon a month that is chosen I need to retrieve data from the tables for the previous six months. How would I accomplish this in MSSQL?
priceHistory200812
priceHistory200811
priceHistory200810 etc....
Based upon a month that is chosen I need to retrieve data from the tables for the previous six months. How would I accomplish this in MSSQL?
ASKER
I created a string with the "SELECT prichist200809 " in it and then I did an EXEC(@sqlString). This worked.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is there a reason that the data was broken into separate tables based on month? At first glance it sounds like a good idea, but as you have found it can complicate data retrieval.