Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Another SQL Server 2000 Query Conundrum
Message
 
À
24/07/2007 10:06:41
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01243142
Message ID:
01243172
Vues:
24
This message has been marked as the solution to the initial question of the thread.
>In the final result set, I need all fields from table3, I also need all fields from table 2 eventually, but to pick out the appropriate matching records from table3 I only need the vehi_id field in the result set that creates qry2.
>
>However, with your code changes, I still receive the error: "The column 'inci_id' was specified multiple times for 'qry2' which baffles me because the qry2 result qry is identical as when it id run alone. The only thing I am doing is putting it inside of the () inner join statement in the final query.

Sorry, my mistake, you must use ALIAS in field list and WHEREs not actual table names
SELECT vh.* from table3 as vh
 inner join  (SELECT tw.veh_id FROM table1 tw
                     INNER JOIN (SELECT table2.inci_id FROM table2
                                        WHERE  table2.inci_id = '07000244      '
                                            or table2.inci_id = '2007093878    '
                                            or table2.parent_id = '07000244      '
                                            or (LEN(table2.parent_id)>0 AND table2.parent_id = '2007093878    ')) qry1
                     ON tw.inci_id = qry1.inci_id WHERE canccode='    ') qry2
on vh.vehi_id = qry2.veh_id
If you want all fields form table2 try this:
SELECT * from table3 as vh
 inner join  (SELECT tw.veh_id, qry1.* FROM table1 tw
                     INNER JOIN (SELECT table2.* FROM table2
                                        WHERE  table2.inci_id = '07000244      '
                                            or table2.inci_id = '2007093878    '
                                            or table2.parent_id = '07000244      '
                                            or (LEN(table2.parent_id)>0 AND table2.parent_id = '2007093878    ')) qry1
                     ON tw.inci_id = qry1.inci_id WHERE canccode='    ') qry2
on vh.vehi_id = qry2.veh_id
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform