Good morning all,
I am running into a syntax error ( [datasource.error] microsoft sql: incorrect syntax near '>'. ) I tried multiple ways to fix this error before posting but I am at dead end.
Sub RunQuery()
Dim QueryText As String
QueryText = " "
QueryText = QueryText + "USE DataBaseName;"
QueryText = QueryText + "GO"
QueryText = QueryText + " "
QueryText = QueryText + "EXEC dbo.StoredProcedure"
QueryText = QueryText + "@BeginDate >= '" & ActiveSheet.Range("B3") & "' "
QueryText = QueryText + "@EndDate <= '" & ActiveSheet.Range("B4") & "' "
QueryText = QueryText + "GO"
QueryText = QueryText + " "
QueryText = QueryText + "select * from ##TempTableFromStoredProcedure"
ActiveWorkbook.Queries("Query1").Formula = _
"let" & Chr(13) & "" & Chr(10) & " Source = Sql.Database(""ServerName"", "" DataBaseName "", [Query=""" & QueryText & """, CreateNavigationProperties=false])" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
ActiveWorkbook.RefreshAll
End Sub
I am running into a syntax error ( [datasource.error] microsoft sql: incorrect syntax near '>'. ) I tried multiple ways to fix this error before posting but I am at dead end.
Sub RunQuery()
Dim QueryText As String
QueryText = " "
QueryText = QueryText + "USE DataBaseName;"
QueryText = QueryText + "GO"
QueryText = QueryText + " "
QueryText = QueryText + "EXEC dbo.StoredProcedure"
QueryText = QueryText + "@BeginDate >= '" & ActiveSheet.Range("B3") & "' "
QueryText = QueryText + "@EndDate <= '" & ActiveSheet.Range("B4") & "' "
QueryText = QueryText + "GO"
QueryText = QueryText + " "
QueryText = QueryText + "select * from ##TempTableFromStoredProcedure"
ActiveWorkbook.Queries("Query1").Formula = _
"let" & Chr(13) & "" & Chr(10) & " Source = Sql.Database(""ServerName"", "" DataBaseName "", [Query=""" & QueryText & """, CreateNavigationProperties=false])" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
ActiveWorkbook.RefreshAll
End Sub