Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Complicated SQL statement
Message
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 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01305759
Message ID:
01305796
Vues:
12
>>>I have a compliated SQL issue. I am using SPT to an iseries database.
>>>
>>>I need a report of users Quality Stamp Numbers, preferment and contractors. 99 percent of the users names are in our HR database. I join the names Database with Quality Assurance Stamp numbers database with matches on badge number. The other 1 percent of users are contractors, their names are in another database.
>>>
>>>How do I get the user names from two different datasources in one SQL statement?
>>
>>
>>SELECT .....;
>>FROM ....;
>>INNER JOIN (SELECT .... FROM HRSource;
>>            UNION
>>            SELECT .... FROM Contractors) Tbl1
>>ON ........
>>
>
>UNION ALL <g>

Why?
If Steven has the same guy in BOTH tables the result will be filtered. There is no need to have TWO records for ONE person. You'll get wrong results:
CLOSE DATA ALL
SET ENGINEBEHAVIOR 90
CREATE CURSOR crsTest (badge int)
INSERT INTO crsTest VALUES (1)
INSERT INTO crsTest VALUES (2)
INSERT INTO crsTest VALUES (3)


CREATE CURSOR crsHR (badge int, Name C(20))
INSERT INTO crsHR VALUES (1, 'Guy 1')
INSERT INTO crsHR VALUES (2, 'Guy 2')


CREATE CURSOR crsContr (badge int, Name C(20))
INSERT INTO crsContr VALUES (1, 'Guy 1')
INSERT INTO crsContr VALUES (3, 'Guy 3')


SELECT crsTest.badge, Tbl1.Name;
 FROM crsTest;
INNER JOIN (SELECT badge, Name FROM crsHR;
            UNION;
            SELECT badge, Name FROM crsContr) Tbl1;
ON crsTest.badge = Tbl1.badge

SELECT crsTest.Badge, Tbl1.Name FROM crsTest;
INNER JOIN (SELECT badge, Name FROM crsHR;
            UNION ALL;
            SELECT badge, Name FROM crsContr) Tbl1;
ON crsTest.badge = Tbl1.badge  && Two records for Badge # 1
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