Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SELECT-SQL
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00500998
Message ID:
00501005
Vues:
21
>I have some code that looks like this:
>
>
>SELECT collections1.bankname, collections1.portfolio, collections1.companyid ,;
>	SUM(IIF(NOT EMPTY(collections1.settdate), 1, 0)) AS tot_col, ;
>	SUM(IIF(INLIST(trancode, '21', '22', '31', '32'), collections1.amount, 0000000000.00)) AS nCredit, ;
>	SUM(IIF(INLIST(trancode, '21', '22', '31', '32'), 1, 0)) AS nCreditnum, ;
>	SUM(IIF(INLIST(trancode, '26', '27', '36'), collections1.amount, 0000000000.00)) AS nDebit, ;
>	SUM(IIF(INLIST(trancode, '26', '27', '36'), 1, 0)) AS nDebit_num ;
>	FROM collections1 ;
>	WHERE collections1.portfolio = cBank ;
>	GROUP BY collections1.companyid ;
>	INTO TABLE c:\dis_collections
>
>*COPY TO mis_collections TYPE XL5
>USE IN dis_collections
>USE IN collections1
>
>
>SELECT dis_collections.*, companyid.bankname AS bank, companyid.companyid AS newid ;
>	FROM FORCE dis_collections LEFT OUTER JOIN \\Svrpc-stlmnt01\e\RETURN-Items\DATA\companyid ;
>	ON ALLTRIM(dis_collections.companyid) == ALLTRIM(companyid.companyid) ;
>	ORDER BY dis_collections.bankname  ;
>	INTO TABLE dis_collections1
>
>USE IN dis_collections
>USE IN dis_collections1
>USE IN companyid
>
>USE dis_collections1 IN 0
>SELECT dis_collections1
>SCAN
>
>	REPLACE bank WITH bankname FOR ISNULL(bank)
>	REPLACE bank WITH "KEY" FOR bankname = "KEY"
>	REPLACE bank WITH "UMB" FOR bankname = "UMB"
>	REPLACE bank WITH "ZIONS" FOR bankname = "ZIONS"
>
>ENDSCAN
>GO TOP
>COPY TO c:\dis_collections1 TYPE XL5
>USE IN dis_collections1
>
>
>I need to do this for 4 other tables. I will then combine them into on table. IS there an easy way to get all this information in one SELECT and combine them later?
>
>Thanks in advance for your help!

If you are talking about applying the first SQL on 4 other tables then executing the same followup code on it as you do the first, then yes you can. Create the additional 4 SQL commands as you did the first and make all 5 SQL commands into 1 SQL using a UNION between all 5.

SELECT...FROM COLLECTIONS1...UNION SELECT...FROM COLLECTIONS2...UNION SELECT...FROM COLLECTIONS3...UNION SELECT...FROM COLLECTIONS4...UNION SELECT...FROM COLLECTIONS5...INTO TABLE WHATEVER

As long as the data types for all field types in each SELECT are identical and in the same order, this should work.
Mark McCasland
Midlothian, TX USA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform