Create Procedure NoNeedForAnSP @myValue int > as >select TableP.*, tableX.FK, tableX.sales > from tableP inner join > (select * from tableA > union > select * from tableB > union > select * from tableC > union > select * from tableD) tableX >on tableP.PK = tableX.FK >where tableP.PK = @myValue>
select * from tableP inner join tableA on tableP.PK = tableA.FK where tableP.PK = @myValue union select * from tableP inner join tableB on tableP.PK = tableB.FK where tableP.PK = @myValue union select * from tableP inner join tableC on tableP.PK = tableC.FK where tableP.PK = @myValue union select * from tableP inner join tableD on tableP.PK = tableD.FK where tableP.PK = @myValueWhich probably would be more effective. Or:
select TableP.*, tableX.FK, tableX.sales from tableP inner join (select * from tableA where tableA.FK = @myValue union select * from tableB where tableB.FK = @myValue union select * from tableC where tableC.FK = @myValue union select * from tableD where tableD.FK = @myValue ) tableX on tableP.PK = tableX.FKCetin