Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting sequential sick persons
Message
De
18/09/2007 09:40:21
 
 
À
18/09/2007 09:12:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01255094
Message ID:
01255107
Vues:
12
How about this:
LOCAL lnCnt AS Integer, lcDisease AS String
lnCnt = 1
lcDisease = ""

CREATE CURSOR sicks (personid i, disease c(15))
INSERT INTO sicks VALUES (883554,'rabies')
INSERT INTO sicks VALUES (128748,'inflammation')
INSERT INTO sicks VALUES (123654,'angina')
INSERT INTO sicks VALUES (146528,'angina')
INSERT INTO sicks VALUES (918457,'rabies')
INSERT INTO sicks VALUES (585846,'rabies')
INSERT INTO sicks VALUES (931694,'inflammation')
INSERT INTO sicks VALUES (123654,'inflammation')
INSERT INTO sicks VALUES (325896,'angina')
INSERT INTO sicks VALUES (513258,'rabies')
INSERT INTO sicks VALUES (652845,'drill')
INSERT INTO sicks VALUES (254636,'angina')
INSERT INTO sicks VALUES (842169,'angina')
INSERT INTO sicks VALUES (195499,'rabies')
INSERT INTO sicks VALUES (585842,'rabies')
INSERT INTO sicks VALUES (128788,'drill')
INSERT INTO sicks VALUES (124558,'angina')
INSERT INTO sicks VALUES (931695,'inflammation')

CREATE CURSOR curSameDisease (Disease C(15), nCount I)

SELECT Sicks.* FROM Sicks INTO CURSOR curSicks ORDER BY Sicks.PersonId

lcDisease = UPPER (ALLTRIM (curSicks.Disease))
SKIP IN curSicks

DO WHILE NOT EOF ("curSicks")
	IF UPPER (ALLTRIM (curSicks.Disease)) == lcDisease
		lnCnt = lnCnt + 1
		SELECT curSameDisease
		LOCATE FOR ALLTRIM (curSameDisease.Disease) == lcDisease
		
		IF FOUND ("curSameDisease")
			REPLACE nCount WITH nCount + 1
		ELSE
			INSERT INTO curSameDisease (Disease, nCount) VALUES (lcDisease, lnCnt)
		ENDIF
		
		SELECT curSicks
	ELSE
		lnCnt = 1
	ENDIF
	
	lcDisease = UPPER (ALLTRIM (curSicks.Disease))
	SKIP IN curSicks
ENDDO

USE IN curSicks
SELECT curSameDisease
BROWSE
HTH

>Program for laboratory
>
>I have a table with two fields: personid and disease.
>This table contain only the person that diagnosed sick for one disease or more and the diagnosed diseases (Person can be sick for more than 1 disease).
>
>I want to find persons that sick for same disease of the next/previous personid (if they tested togother maybe the tubes mixed).
>In the following examle I will get the persons 931694/5 sicks for same disease.
>
>
CREATE CURSOR sicks (personid i, disease c(15))
>INSERT INTO sicks VALUES (883554,'rabies')
>INSERT INTO sicks VALUES (128748,'inflammation')
>INSERT INTO sicks VALUES (123654,'angina')
>INSERT INTO sicks VALUES (146528,'angina')
>INSERT INTO sicks VALUES (918457,'rabies')
>INSERT INTO sicks VALUES (585846,'rabies')
>INSERT INTO sicks VALUES (931694,'inflammation')
>INSERT INTO sicks VALUES (123654,'inflammation')
>INSERT INTO sicks VALUES (325896,'angina')
>INSERT INTO sicks VALUES (513258,'rabies')
>INSERT INTO sicks VALUES (652845,'drill')
>INSERT INTO sicks VALUES (254636,'angina')
>INSERT INTO sicks VALUES (842169,'angina')
>INSERT INTO sicks VALUES (195499,'rabies')
>INSERT INTO sicks VALUES (585842,'rabies')
>INSERT INTO sicks VALUES (128788,'drill')
>INSERT INTO sicks VALUES (124558,'angina')
>INSERT INTO sicks VALUES (931695,'inflammation')
>
>PS
>If it's possible, I prefer to get it by count group (2sequential persons for same disease,3,4..)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform