| | |
comparing records
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 23
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2007
Posts: 22
Reputation:
Solved Threads: 5
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.
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)
Private Sub Command1_Click() Dim aConn As ADODB.Connection Set aConn = New ADODB.Connection aConn.ConnectionString = "DSN=XYZ;" aConn.Open Dim rs As ADODB.Recordset Dim sSQL As String sSQL = "SELECT col1, col2 FROM t1 " & _ "GROUP BY col1, col2 " & _ "HAVING COUNT(*) > 1" Set rs = New ADODB.Recordset Call rs.Open(sSQL, aConn) Do While Not rs.EOF MsgBox "More than one record with columnvalues Col1:" & rs(0) & " Col2:" & rs(1) rs.MoveNext Loop rs.Close End Sub
•
•
Join Date: Jun 2007
Posts: 22
Reputation:
Solved Threads: 5
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.
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)
Private Sub Command2_Click() Dim aConn As ADODB.Connection Set aConn = New ADODB.Connection aConn.ConnectionString = "DSN=VPE;" aConn.Open Dim rs1 As ADODB.Recordset Dim rs2 As ADODB.Recordset Dim sDups As String Dim sSQL1 As String Dim sSQL2 As String Dim iCnt As Integer sDups = "" iCnt = 0 sSQL1 = "SELECT keycol, fprintcol FROM table1 ORDER BY keycol" Set rs1 = New ADODB.Recordset Call rs1.Open(sSQL1, aConn) Do While Not rs1.EOF sSQL2 = "SELECT keycol, fprintcol FROM table1 WHERE keycol <> '" & rs1!keycol & "'" Set rs2 = New ADODB.Recordset Call rs2.Open(sSQL2, aConn) Do While Not rs2.EOF 'comparing, for example: If rs2!fprintcol = rs1!fprintcol Then 'do not remember the same key multiple times If InStr(sDups, "|" & Trim(rs1!keycol)) = 0 Then sDups = sDups & "|" & Trim(rs1!keycol) iCnt = iCnt + 1 End If End If rs2.MoveNext Loop rs1.MoveNext Loop MsgBox Replace(sDups, "|", vbLf) End Sub
![]() |
Similar Threads
- PHP help in creating profile thingy (PHP)
- dropdownlist value doesnt get selected (ASP)
- Comparing 2 files and then apending matches (Shell Scripting)
- Extending A Class (Python)
- how do i update to Access db? (C#)
- Little help Comparing Strings (C++)
- Comparing and sorting of Dates. (C++)
- Trojan.Bookmarker.gen/about:blank (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Image on MDI..
- Next Thread: data not fetched after getting inserted in access database
Views: 732 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






