Satu-satunya cara, tanpa membuat kueri secara dinamis, adalah dengan membuat kode keras di setiap kombinasi dan memilih yang Anda inginkan.
Jika nama tabel adalah parameter untuk prosedur tersimpan, ini bisa dalam blok IF. Tapi rasanya kikuk.
Jika bidang dari setiap tabel sama, Anda dapat menyatukan tabel dan memilih dari...
CREATE VIEW myUnifiedStructure AS
SELECT 'Table1' AS tableName, * FROM Table1
UNION SELECT 'Table2' AS tableName, * FROM Table2
UNION SELECT 'Table3' AS tableName, * FROM Table3
-- etc
SELECT * FROM myUnifiedStructure WHERE tableName = 'Table1'
Jika bidang berbeda di setiap tabel, Anda mungkin hanya tertarik pada sebagian bidang...
CREATE VIEW myUnifiedStructure AS
SELECT 'Table1' AS tableName, field1 AS field1, field4 AS field2 FROM Table1
UNION SELECT 'Table2' AS tableName, field2 AS field1, field3 AS field2 FROM Table2
UNION SELECT 'Table3' AS tableName, field2 AS field1, field4 AS field2 FROM Table3
-- etc
Atau Anda dapat memberikan NULL untuk bidang yang tidak ada di tabel sumber...
CREATE VIEW myUnifiedStructure AS
SELECT 'Table1' AS tableName, NULL AS field1, field2 AS field2 FROM Table1
UNION SELECT 'Table2' AS tableName, field1 AS field1, field2 AS field2 FROM Table2
UNION SELECT 'Table3' AS tableName, field1 AS field1, NULL AS field2 FROM Table3
-- etc