SQL VBA - Text Files

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
I have built code that will query fields from text files. I have 2 text files (avTable) & (rtTable).

The following SQL statement works great:
Code:
GetJoinQuery = Join$(Array( _
        "SELECT av.Date, av.Hour, rt.AvgRate", _
        "FROM `" & avTable & "` av, `" & rtTable & "` rt ", _
        "WHERE av.Date = rt.DateOf AND av.Hour = rt.Hour ", _
        "ORDER BY av.Date, av.Hour"), vbCrLf)

These 2 tables contain dates, hours, and rates. avTable has complete data (ie all hours for every date), rtTable does not. What SQL statement will return me a recordset that has Date, Hour, AvgRate from the rtTable and Date, Hour, AvgRate from the avTable when the rtTable does not have that item (ie Hour). Note field names are different: avTable Field names = Date, Hour, Average; rtTable field names = DateOf, Hour, AvgRate.

For exampl: rtTable has for 1/1/2011 an avgRate for hours 1, 2, & 4. I want a recordset that has those data points but then also the missing hour 3 from the avTable. So my new recordset will have Date, hour, Rate for 1/1/2011 hours 1, 2, 3, & 4
I hope I makes sense.
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

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