I have a scenario in which I have to query an excel sheet using SQL.
In excel I have a column called “test_case_id”, which holds alphanumeric value
I use the following vbscript code to get the values from excel.
The “test_case_id” column in excel has been formatted as “General”.
When the value for this column is an integer ( ex: 1,2,3… )
SELECT * FROM [05 Invest Allocate$] WHERE [test_case_id] =1
The above query seems to work
But when the “test_case_id” column has a character in it ( ex: 5b, 6b,7b)
SELECT * FROM [05 Invest Allocate$] WHERE [test_case_id] ='5b'
the above query gives an error “Data type mismatch in criteria expression.”
Could some one please help me resolve this in such a way that i can query either as a string or as an integer in the where clause ?
Full code is :
strQuery = "SELECT * FROM [05 Invest Allocate$] WHERE [test_case_id] ='5b'"
j_drive_root_path="C:\Documents and Settings\Desktop\"
Set objNetwork = CreateObject("WScript.Network")
strUserName =objNetwork.UserName
Set fso = CreateObject("Scripting.FileSystemObject")
Set original = fso.GetFile(j_drive_root_path & "temp_invest_allocate.xls")
strCopyPath = "C:\Documents and Settings\" & strUsername & "\copyofexceltable.xls"
original.Copy (strCopyPath)
'Set the connection object and path to the copied spreadsheet
Set objAdCon = CreateObject("ADODB.Connection")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strCopyPath & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"""
'Open spreadsheet
objAdCon.Open strConn
'Create a recordest object (to store the results of the query)
Set record_set = CreateObject("ADODB.Recordset")
'Run the query
record_set.CursorLocation = 3
record_set.Open strQuery, objAdCon, 1, 3
If Not record_set.EOF Then
Set client_to_accountID = CreateObject("Scripting.Dictionary")
client_to_accountID.CompareMode=vbTextCompare
client_to_accountID.RemoveAll
Do Until record_set.EOF
tmp_val=Trim(Cstr(record_set("id").Value))
print "id=" & tmp_val
record_set.MoveNext
Loop
End If ' End of if not record_set.EOF
In http://support.microsoft.com/kb/257819 it states:
You may need to change TypeGuessRows to 0 in the registry at