SQL to count double quotes in a text file

Deutz

Board Regular
Joined
Nov 30, 2009
Messages
196
Office Version
  1. 365
Platform
  1. Windows
Hi and thanks in advance,

I am using Excel 2010 and have some vba that writes values in a column to a text file. When I write to the file I enclose each value in double quotes. If there is no value in the cell then I just write two sets of double quotes to the file. I then want to run some SQL on the text file to return a count of instances where there is no data, where there is just the two double quotes "". I have tried a number of variations of WHERE criteria but I always get back a count of zero despite there being a couple of rows in the text file which contain the two double quotes.

Code:
Open ThisWorkbook.Path & "\myTextFile.txt" For Output As 1
Print #1, Chr(34) & "Test" & Chr(34)
For Each rng In rngSel
    Print #1, Chr(34) & rng & Chr(34)
Next rng
Close #1
Set db1 = CreateObject("ADODB.Connection")
db1.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=" & ThisWorkbook.Path & ";"
strSQL = "SELECT  Count([Test]) as myCount "
strSQL = strSQL & "FROM [myTextFile.txt] "
strSQL = strSQL & "WHERE [Test] = '" & Chr(34) & Chr(34) & "'"<!-- END TEMPLATE: bbcode_code -->
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Fazza,

Tried Is Null but that still returns zero despite there being two rows in the text file with nothing but ""
 
Upvote 0
Think I have solved this by subtracting count of values from total rows ...

Code:
strSQL = "SELECT  " & lngTotalRows & "-Count([Test]) "
strSQL = strSQL & "FROM [777.txt] "
strSQL = strSQL & "WHERE [Test] IS NOT NULL"<!-- END TEMPLATE: bbcode_code -->
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top