Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need to combine 3 child records into 1 record
Message
 
À
17/12/1999 10:18:41
Shane Gilbert
Oklahoma State Department of Education
Norman, Oklahoma, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00304928
Message ID:
00305395
Vues:
23
Boy Shane, your scenario is definitely no joy in fox's implementation of SQL. This isn't exactly graceful, but here's how you could get it to work.
SELECT a.ifspid, b.svc_type, COUNT(*) AS total_cnt ;
FROM ifsp a, ifsp_svc b ;
WHERE a.ifspid= b.ifspid ;
GROUP BY a.ifspid ;
INTO CURSOR Step1

SELECT a.ifspid, b.svc_type, b.freq, b.startdate, 0 as cnt_me, c.total_cnt ;
FROM ifsp a, ifsp_svc b, step1 c ;
WHERE a.ifspid= b.ifspid ;
AND a.ifspid= c.ifspid ;
ORDER by a.ifspid, b.svc_type ;
INTO CURSOR Step2

USE DBF('Step2') AGAIN ALIAS Step3 IN 0

SELECT Step3
LOCAL ipointer

DO WHILE NOT EOF()
	ipointer = step3.total_cnt
	FOR m.cnt_me = 1 to ipointer 
		GATHER MEMVAR FIELD cnt_me
		SKIP
	ENDFOR
	SCATTER MEMVAR FIELD cnt_me
ENDDO

SELECT ifspid, svc_type AS svc_typ1, freq AS freq1, startdate AS start1, ;
00 AS svc_typ2, 00 AS freq2, {  /  /  } AS start2, ; 
00 AS svc_typ3, 00 AS freq3, {  /  /  } AS start3 ; 
FROM step3 ;
WHERE cnt_me = 1 ;
UNION ;
SELECT ifspid, 00 AS svc_typ1, 00 AS freq1, {  /  /  } AS start1, ;
svc_type AS svc_typ2, freq AS freq2, startdate AS start2, ; 
00 AS svc_typ3, 00 AS freq3, {  /  /  } AS start3 ; 
FROM step3 ;
WHERE cnt_me = 2 ;
UNION ;
SELECT ifspid, 00 AS svc_typ1, 00 AS freq1, {  /  /  } AS start1, ;
00 AS svc_typ2, 00 AS freq2, {  /  /  } AS start2, ; 
svc_type AS svc_typ3, freq AS freq3, startdate AS start3 ; 
FROM step3 ;
WHERE cnt_me = 3 ;
INTO CURSOR step4

SELECT ifspid, SUM(svc_typ1) AS svc_typ1, SUM(freq1) AS freq1, ;
MAX(start1) AS start1, SUM(svc_typ2) AS svc_typ2, SUM(freq2) AS freq2, ;
MAX(start2) AS start2, SUM(svc_typ3) AS svc_typ3, SUM(freq3) AS freq3 ;
FROM step4 ;
GROUP BY ifspid INTO CURSOR RoxResult
Like I said... no joy. Maybe somebody else can look at this and pipe up a better way. HTH.
Roxanne M. Seibert
Independent Consultant, VFP MCP

Code Monkey Like Fritos
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform