troubleshooting Question

VBscript to Compare Recordset Fields.

Avatar of ggmisadmin
ggmisadmin asked on
Visual Basic Classic
4 Comments1 Solution3938 ViewsLast Modified:
Hello everybody, hope you can help with this.
I am trying to write a VBScript using ADO to connect to a SQL database and use two recordset objects to  compare two fields named "PhoneNumber" on two different tables. Both fields on each table are Varchar (20), but even if I know there are matching phone numbers, I can not find any of them. This is the script:

 Option Explicit
Dim objConn
Dim objRs
Dim objTisnaRs
Dim strSQL
DIM strTisnaSQL
set objConn=CreateObject("ADODB.Connection")
objConn.Open "Provider=sqloledb;"&_
           "Data Source=192.168.150.5;"&_
           "Initial Catalog=CDR_Analysis;"&_
           "Integrated Security=SSPI"
set objRs=createObject("ADODB.Recordset")
set objTisnaRs=CreateObject("ADODB.Recordset")
strSQL="SELECT phonenumber FROM FirstTable WHERE City LIKE 'Guayaquil'"
strTisnaSQL="SELECT PhoneNumber FROM SecondTable WHERE City='ECUADOR GUAYAQUIL'"
set objRs=objConn.Execute(strSQL)
set objTisnaRs=objConn.Execute(strTisnaSQL)
objRs.movefirst
objTisnaRs.movefirst
Do While Not objTisnaRs.eof
  IF objRs!PhoneNumber=objTisnaRs!PhoneNumber Then
        msgbox "Matching number found" & objRs("PhoneNumber")
       Else
objTisnaRs.movenext   'go to the next entry
 End If
loop
objTisnaRs.movefirst  're-start from the beginning
objRs.movenext
Loop
msgbox "no match found for"

I tried also different syntax for recordset  such as objRs.fields("PhoneNumber").value but with no luck.
Both tables have "PhoneNumber" data type as Varchar(20).
 
Thank you for your help....

   
ASKER CERTIFIED SOLUTION
leonstryker
VP

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros