Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparing two tables
Message
From
22/08/2009 18:56:19
 
 
To
22/08/2009 17:50:16
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01419830
Message ID:
01419866
Views:
83
I thought you were referring to the structures of the tables. For data, you could write something yourself and output it to a table or to a display in a form or to whatever - here's an example to get you started:
clear
CLOSE tables
USE tableactive IN 0 ALIAS table1
USE tablehistory IN 0 ALIAS table2
select table1
=AFIELDS(tafields,'table1')
SET EXACT ON
SCAN  && change this if you need to do a locate or seek in the 2nd table but you get the picture
	*--Go to the correct record in both that should match (Locate, SEEK, etc. this example just goes by recno)
	lnRecno = RECNO('table1')
	GOTO lnRecno IN table2
	FOR i = 1 TO ALEN(tafields,1)
		DO CASE
		CASE tafields(i,2) = "C" OR tafields(i,2) = "M"
			SELECT table1
			lxValue1 = UPPER(ALLTRIM(NVL(EVALUATE(tafields(i,1)),'')))
			SELECT table2
			lxValue2 = UPPER(ALLTRIM(NVL(EVALUATE(tafields(i,1)),'')))
		CASE tafields(i,2) = "I" OR tafields(i,2) = "N"
			lxValue1 = NVL(table1.&tafields(i,1),0)
			lxValue2 = NVL(table2.&tafields(i,1),0)
		*--Etc More CASE statements
		ENDCASE
		IF lxValue1 <> lxValue2
			?  [Record: ]
			?? ALLTRIM(STR(lnRecno))
			?? [ Field: ] +tafields(i,1)+ [ Differ: ]
			?? lxValue1
			?? [ != ]
			?? lxValue2
		ENDIF
	ENDFOR
	SELECT table1
	IF RECNO('table1') <> lnrecno
		goto lnrecno IN table1
	ENDIF
ENDSCAN
>Sergey --
>
>Looks to be like the download you referenced is not exactly what I am looking for -- it does a nice comparison of the structure of two tables, but, from what I am able to see, does not compare the actual data.
>
>Will try XML and Beyond Compare next
>
>>Jim,
>>
>>Check file #25036.
>>Another option would be to convert tables to XML with CURSORTOXML() and use text compare utility of your choice. I would recommend BeyondCompare
>>
>>>I have copies of the same table as it existed last weekend and this weekend.
>>>
>>>Sometime between then and now, a number of fields for a number of records have been destroyed. At the moment I have no idea how this happened, which fields are involved, nor how many records got trashed.
>>>
>>>The file is of moderate size -- about 10,000 records for about 150 fields.
>>>
>>>Is there any handy utility that will help me identify changed fields and records between the two?
>>>
>>>Thanks in advance.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform