Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compare fields between 2 records of a cursor
Message
De
12/03/2012 15:09:52
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01538081
Message ID:
01538105
Vues:
53
>I need to compare a subset of fields in two records of the same cursor to create output where record1.field not equal record2.field. The best way I can think of is to scatter fields from each rec to separate arrays then do a for ... next loop comparing the values and kicking out field names from a matching array of the ones that are different.
>
>I already know some will always be different so sys(2017) won't help here. I thought there was another function to compare fields but I can't remember or find it. (It's Monday.)
>
>Anyone got a better idea?

I can't think of an elegant way to do it in one line of SQL, but you can use SELECT DISTINCT in a similar way to what you're proposing:
CREATE CURSOR Output ;
	( ColName C( BigEnough ) )

SELECT ;
	ColumnsOfInterest ;
	FROM SourceCursor ;
	WHERE SourceCursor.PKey IN ( Value1, Value2 ) ;
	INTO CURSOR TestRows

lnColCount = AFIELDS( laFields, "TestRows" )

FOR lnIx = 1 TO lnColCount STEP 1
	lcSQLCmd = "SELECT DISTINCT " + laFields[ lnIx, 1 ] + " FROM TestRows INTO CURSOR _Temp"
	
	&lcSQLCmd
	
	IF _TALLY > 1
		INSERT INTO Output ;
			( ColName ) ;
			VALUES ;
				( laFields[ lnIx, 1 ] )
	
	ENDIF
	
	USE IN _Temp
	
ENDFOR

USE IN TestRows
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform