Howdy...
Not sure I'm in the right place for this one guys & gals - So if I am lost please kindly redirect - Thanks
I'm developing a SQL select statement in Excel to provide a value for a variable used in a second SQL select statement.
My approach to this is to get both SQL statements to work and then combine them...They both work but trying to combine them has led me here
Below is my first SQL statement - Which, when test separately works perfectly as it places the TOP (1) or (2) or (3) in my excel sheet
Code:
StrSQL1 = "SELECT TOP (1) [BatchID]" & _
"FROM [MyServer].[Schema].[TblData]" & _
"WHERE BatchID >= '20190114_050000 AND BatchID<= '20190114_060000'"
What I'm trying to design here is a way to pull just the first data load in the 5 AM hour
where, depending on the day and volume can be 3-4 runs at various times within the hour.
The below also works perfectly as it places the entire RecordSet in my excel sheet as well...
Code:
StrSQL2 = "SELECT [ReportDate], [SalesType], [TotalSales]" & _
"FROM [MyServer].[Schema].[TblData]" & _
"WHERE BatchID = '20190114_052356'"
As you can see the immediate above is hard coded
What I'm trying to get to work is something like the below
Code:
StrSQL2 = "SELECT [ReportDate], [SalesType], [TotalSales]" & _
"FROM [MyServer].[Schema].[TblData]" & _
"WHERE BatchID = 'StrSQL1' "
I've tried several variations of assigning the RecordSet value of StrSQL1 to a variable (Dim'ing Strings, Collections, Etc) then replacing the hard coded BatchID with the Variable
And, well, I'm here so you know how well that's working...
Thanks As always for any help
RT91