The rows in a properly designed table contain attributes of a business entity that each row in the table models. If you have two tables which are identical in structure, then they almost assuredly model the same thing, and so should be combined into the same table. If you can discern which of two tables contains the entity you are looking for, then you should embody that which distingushes them from one another into another attribute (column) of the same table.
Quote:
quote:
I have multiple tables within a database that are identical in layout, but have different data that needs to remain in separate tables
|
Why do they have to be in separate tables?
The only way to do what you ask in a stored procedure is to use dynamic SQL. That is, you would pass the table name in as a character string parameter, then build up the SQL string by concatenating the parameter(table name) with the rest of the SQL statement, then execute the resultant local string variable.
This is slow, and is a severe security risk, as the stored procedure opens your system up to an SQL injection attack. Furthermore, using a stored procedure is an efficient operation because the stored procedure is compiled once when it is first executed and then the query plan is cached so that it can be quickly re-utilized on subsequent calls. Using dynamic SQL guarantees that this efficiency cannot be realized.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com