Timely insight needed.
Using a relatively long sql script within MS Excel vba to extract data from a Sql Server database.
If I input the sql script on one line, as displayed below, I am able to run without any errors
However, if I input the sql script on multiple lines, as displayed below, I continue to receive the error
"Incorrect syntax near the keyword between."
The cause of the error appears to be related to the format of the dates, but I cannot just yet resolve.
I did review the list of references and do indeed have "Microsoft Active Data Objects 2.8 Library."
What modifications are needed to successfully run the sql script?
Using a relatively long sql script within MS Excel vba to extract data from a Sql Server database.
If I input the sql script on one line, as displayed below, I am able to run without any errors
Code:
SQL = "Select top 10 AccountNo,Name,Debit_Start,Debit_End from Sales where Process_Date between '2014-04-01' and '2015-03-31' and Invoice_No = '123457' Group by AccountNo,Name,Debit_Start,Debit_End"
However, if I input the sql script on multiple lines, as displayed below, I continue to receive the error
"Incorrect syntax near the keyword between."
Code:
SQL = "Select top 10 AccountNo,Name,Debit_Start,Debit_End" & _
"from Sales " & _
"where Process_Date between '2014-04-01' and '2015-03-31' " & _
"and Invoice_No = '123457' " & _
"Group by AccountNo,Name,Debit_Start,Debit_End"
The cause of the error appears to be related to the format of the dates, but I cannot just yet resolve.
I did review the list of references and do indeed have "Microsoft Active Data Objects 2.8 Library."
What modifications are needed to successfully run the sql script?