|
-
May 31st, 2015, 08:48 AM
#4
Thread Starter
Lively Member
Re: Deleting rows from a CSV file, based on date column value.
Thanks for your reply.
Sam:
My data set is like this:
Column1,Column2,Column3,Column4,Column5, Column6,Column7
data1,data2,data3,data4,Date,data6,data7
data1,data2,data3,data4,Date,data6,data7
data1,data2,data3,data4,Date,data6,data7
....
LaVolpe:
1. I can read a CSV file into a recordset, and succeeded to filter records using SQL string on the rs, but my last column is an elapsed time like 00:03:30 and it converted to time like 12:03:30(and my sample code places quotes at beginning & end of each row I couldn't determine how to remove).
I use CSV convert to RS for Datareports - no problems.
At the moment I'm testing The CSV to RS W/SQL string as below, but in the below, each line has begin & end quotes, and it alters last Elapsed column/field( from 00:03:30 to 12:03:30). Working on it.
Code:
Dim Cn1 As ADODB.Connection 'Simple ADODB RS to CSV file filter demo
Dim rs As New ADODB.Recordset
Dim txt As TextStream
Dim iSQLstring As String
Set Cn1 = New ADODB.Connection
Cn1.ConnectionString = _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DefaultDir=" & "C:\"
Cn1.Open
iSQLstring = "SELECT * FROM Data.csv WHERE Time_On < arDate ORDER BY Elapsed DESC" '-- Has syntax error in FROM clause --
Set rs = Cn1.Execute(iSQLstring)
Open "C:\Test.csv" For Output As #1
While Not rs.EOF
Print #1, rs.Fields(0) & "," & rs.Fields(1) & "," & rs.Fields(2) & "," & rs.Fields(3) & "," & rs.Fields(4) & "," & rs.Fields(5) & "," & rs.Fields(6)
rs.MoveNext
Wend
Close 1
So after changing Write #1 to Print #1, my resulting data lines looks like this:
data1,data2,data3,data4,date1,date2,12:03:30
Then I added the WHERE date in the sql that has an error.
Last edited by Enrique_; May 31st, 2015 at 10:52 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|