943,616 Members | Top Members by Rank

Ad:
Jun 12th, 2008
0

comparing records

Expand Post »
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
Similar Threads
Reputation Points: 4
Solved Threads: 0
Newbie Poster
realone is offline Offline
24 posts
since May 2008
Jun 12th, 2008
0

Re: comparing records

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
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 13th, 2008
0

Re: comparing records

As suggested ,that can be done at database level. No need to any special aglorithm for that.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Jun 16th, 2008
0

Re: comparing records

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.
Reputation Points: 4
Solved Threads: 0
Newbie Poster
realone is offline Offline
24 posts
since May 2008
Jun 16th, 2008
0

Re: comparing records

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
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Image on MDI..
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: data not fetched after getting inserted in access database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC