SQL Process with ODBC Text Driver in VBScript

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

SQL Process with ODBC Text Driver in VBScript

Post by armsys »

Hi,
The following code runs perfectly in Macro Scheduler: :hairout:

Code: Select all

Timer>Start
GoSub>GetSumFromCSV
Timer>stop
Let>TotalTime=%stop%-%start%
MDL>Time to Process = %TotalTime%%crlf% Records = %num_recs%  %num_fields%  Sum = %Sum_1_1%
SRT>GetSumFromCSV
  **Let>ConStr=Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=C:\ArmSys\ODBC\;
  Let>ConStr=Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\ArmSys\ODBC\;
  DBConnect>ConStr,dbH
  Let>sql=select SUM(%ColumnNameToSum%)from armsys.txt
  DBQuery>dbH,select SUM(A1) from armsys.txt,Sum,num_recs,num_fields
  DBClose>dbH
END>GetSumFromCSV
The csv file named armsys.txt abvove:

Code: Select all

A1,A2
1,2
3,4
5,6
Request
How to process a csv file with SQL command in VBScript?
Regards,
Armstrong

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SQL Process with ODBC Text Driver in VBScript

Post by HansV »

Can you explain what you want to do? I'm not familiar with Macro Scheduler.
Best wishes,
Hans

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: SQL Process with ODBC Text Driver in VBScript

Post by armsys »

HansV,
Sorry for being foggy. No, Macro Scheduler posted above serves merely as a pseudo code.
In fact, Macro Scheduler can run VBScript directly inside a Macro Scheduler script.
That's why I'm eager to learn about VBscript.
The goal is to sum of all numbers in, say, in Column A1, ie, 1, 3 and 5, in a text (ie CSV) file.
Whereby we can learn how to run any SQL commands in VBScript. For example: SUM(A1) from armsys.txt
Actually, any SQL would do such as SELECT * from armsys.txt.
Regards,
Armstrong

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SQL Process with ODBC Text Driver in VBScript

Post by HansV »

I'm afraid I don't know. I wrote some code that works in VBA, but it refuses to run in VBScript. Sorry.
Best wishes,
Hans

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: SQL Process with ODBC Text Driver in VBScript

Post by armsys »

It's okay. Besides, my request is beyond the scope of the forum.
When I find out the answer, I'll let you know.
Regards,
Armstrong