comparing records

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 23
Reputation: realone has a little shameless behaviour in the past 
Solved Threads: 0
realone realone is offline Offline
Newbie Poster

comparing records

 
0
  #1
Jun 12th, 2008
hi guys,
pls can u help me with an algorithm that we compare record in a database one after the other.As in the first record compare to other records in the database,second record also compare compare with other records in the db,.....................untill all the records are compare.

i want to generate report on record that appear more than once
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: comparing records

 
0
  #2
Jun 12th, 2008
You could use a SQL statement with a GROUP BY ... HAVING clause.
Group the records by the columns that are relevant for "equality". Use HAVING COUNT(*) > 1 to return only those groups that have more than one member = more than one row with the same values in the relevant columns.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Dim aConn As ADODB.Connection
  3. Set aConn = New ADODB.Connection
  4. aConn.ConnectionString = "DSN=XYZ;"
  5. aConn.Open
  6.  
  7. Dim rs As ADODB.Recordset
  8. Dim sSQL As String
  9. sSQL = "SELECT col1, col2 FROM t1 " & _
  10. "GROUP BY col1, col2 " & _
  11. "HAVING COUNT(*) > 1"
  12.  
  13. Set rs = New ADODB.Recordset
  14. Call rs.Open(sSQL, aConn)
  15. Do While Not rs.EOF
  16. MsgBox "More than one record with columnvalues Col1:" & rs(0) & " Col2:" & rs(1)
  17. rs.MoveNext
  18. Loop
  19. rs.Close
  20.  
  21. End Sub
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,134
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: comparing records

 
0
  #3
Jun 13th, 2008
As suggested ,that can be done at database level. No need to any special aglorithm for that.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 23
Reputation: realone has a little shameless behaviour in the past 
Solved Threads: 0
realone realone is offline Offline
Newbie Poster

Re: comparing records

 
0
  #4
Jun 16th, 2008
Thanks very much for the code it will go along way to help.But if i have to be honest with u.i actually need thesame code that will does for image record(Fingerprint). i want to compare one fingerprint to another just like the one u sent for the text field records.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: comparing records

 
0
  #5
Jun 16th, 2008
Please check if the dbms supports grouping for the datatype that is used for the fingerprint column.

If it does not and there is a key in the table to identify each record, ýou may use two loops, as shown below. This solution has a very long runtime if there are many records in the table.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command2_Click()
  2. Dim aConn As ADODB.Connection
  3. Set aConn = New ADODB.Connection
  4. aConn.ConnectionString = "DSN=VPE;"
  5. aConn.Open
  6. Dim rs1 As ADODB.Recordset
  7. Dim rs2 As ADODB.Recordset
  8. Dim sDups As String
  9. Dim sSQL1 As String
  10. Dim sSQL2 As String
  11. Dim iCnt As Integer
  12.  
  13. sDups = ""
  14. iCnt = 0
  15. sSQL1 = "SELECT keycol, fprintcol FROM table1 ORDER BY keycol"
  16. Set rs1 = New ADODB.Recordset
  17. Call rs1.Open(sSQL1, aConn)
  18. Do While Not rs1.EOF
  19. sSQL2 = "SELECT keycol, fprintcol FROM table1 WHERE keycol <> '" & rs1!keycol & "'"
  20. Set rs2 = New ADODB.Recordset
  21. Call rs2.Open(sSQL2, aConn)
  22. Do While Not rs2.EOF
  23. 'comparing, for example:
  24. If rs2!fprintcol = rs1!fprintcol Then
  25. 'do not remember the same key multiple times
  26. If InStr(sDups, "|" & Trim(rs1!keycol)) = 0 Then
  27. sDups = sDups & "|" & Trim(rs1!keycol)
  28. iCnt = iCnt + 1
  29. End If
  30. End If
  31. rs2.MoveNext
  32. Loop
  33. rs1.MoveNext
  34. Loop
  35. MsgBox Replace(sDups, "|", vbLf)
  36. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC