Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JeJo
Starting Member
1 Post |
Posted - 2008-02-05 : 04:49:15
|
| A third party system we work with has twelve identical tables. Lets name them INFO1 to INFO12. I would like to write one (1) query which, with some kind of case statement, is able to join to either of the tables. The SP should have a "JoinWithThisTable" variable.Is there a "native TransactSQL way" - today I build up the query in a varchar and end the store procedure with exec(@query).select p.name, i.somethingfrom person pleft join INFO1 i on i.id = p.idINFO1 could be INFO7, or INFO9, or.. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-05 : 04:50:51
|
| Yeah. Dynamic SQL is the only way if the joining table is unknown until runtime. |
 |
|
|
|
|
|