Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default querying text files with sql

Trying to run a SQL query with ADO involving 2 text files. This works when I
do it with MS Query, but I don't want to put data in a sheet but write a
recordset to a text file.
This is the code I have:

TextConn = "DSN=TextQuery;" 'system DSN

Query5 = "SELECT " & _
"E.ENTRY_ID, " & _
"E.PATIENT_ID, " & _
"E.ADDED_DATE, " & _
"E.READ_CODE " & _
"FROM " & _
"ENTRY.txt E INNER JOIN PATIENT.txt P ON " & _
"(P.PATIENT_ID = E.PATIENT_ID) " & _
"WHERE NOT E.READ_CODE = '' " & _
"ORDER BY 1 ASC"

Set rs = New ADODB.Recordset

rs.Open Source:=Query5, _
ActiveConnection:=TextConn, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnly, _
Options:=adCmdText

Now this fails with the error:
Data type mismatch in criteria expression.
Any idea what could be wrong here?
Have been looking for examples of this on the internet, but haven't found
anything useful sofar.
Thanks for any advice.


RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default querying text files with sql

Forget about this. The code should be:

Query5 = "SELECT " & _
"E.ENTRY_ID, " & _
"E.PATIENT_ID, " & _
"E.ADDED_DATE, " & _
"E.READ_CODE " & _
"FROM " & _
"ENTRY.txt E INNER JOIN PATIENT.txt P ON " & _
"(P.PATIENT_ID = E.PATIENT_ID) " & _
"WHERE NOT E.READ_CODE IS NULL " & _
"ORDER BY 1 ASC"

And then it works fine.
This whole thing of querying text files with SQL is in fact quite nice. It
is quick and easy and is much better than doing it in a worksheet.


RBS


"RB Smissaert" wrote in message
...
Trying to run a SQL query with ADO involving 2 text files. This works when

I
do it with MS Query, but I don't want to put data in a sheet but write a
recordset to a text file.
This is the code I have:

TextConn = "DSN=TextQuery;" 'system DSN

Query5 = "SELECT " & _
"E.ENTRY_ID, " & _
"E.PATIENT_ID, " & _
"E.ADDED_DATE, " & _
"E.READ_CODE " & _
"FROM " & _
"ENTRY.txt E INNER JOIN PATIENT.txt P ON " & _
"(P.PATIENT_ID = E.PATIENT_ID) " & _
"WHERE NOT E.READ_CODE = '' " & _
"ORDER BY 1 ASC"

Set rs = New ADODB.Recordset

rs.Open Source:=Query5, _
ActiveConnection:=TextConn, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnly, _
Options:=adCmdText

Now this fails with the error:
Data type mismatch in criteria expression.
Any idea what could be wrong here?
Have been looking for examples of this on the internet, but haven't found
anything useful sofar.
Thanks for any advice.


RBS


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel (xls) files spontaneously converting to text files Be-jamin Excel Discussion (Misc queries) 0 November 18th 08 05:31 PM
Querying Worksheets thefonz37 Excel Worksheet Functions 5 March 25th 08 04:55 AM
Querying data [email protected] Excel Discussion (Misc queries) 1 February 23rd 07 01:43 PM
Querying 2 Excel files J-Unit Excel Worksheet Functions 1 April 24th 06 05:44 PM
QUERYING ACCESS Drew Excel Discussion (Misc queries) 3 July 13th 05 07:25 AM


All times are GMT +1. The time now is 09:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"