Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
One of four possible children
Message
De
04/10/2007 18:04:05
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01258745
Message ID:
01258766
Vues:
13
>
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
>
>Brilliant Cetin!! Thank you very much.
>Now a followup question (before I give you stars). Your solution works, but at what cost? Does this solution select all the records from TableA, TableB, TableC and TableD and place them into a temporary table TableX?
>
>Thanks,
>Einar

In effect yes. I think your design was wrong from the start. You could partition the table from the start and MSSQL would know which one to put where. You'd be doing a single 2 table join then.

You might also make it as:
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 = @myValue 
Which 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.FK
Cetin

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform