When using RUN QUERY,The SQL query contains variables ‘[統計起始日期]’ and ‘[統計終止日期]’ being passed into the query the error message “Invalid column name ‘統計終止日期’.” and "Invalid column name ‘統計起始日期’.
Your input arguments are of type string, but are not encapsulated by ’
like this: ‘@Startdate’ and ‘@Enddate’
You could either do that or convert your input arguments into type datetime.
If I directly modify the query in the “EDIT QUERY” with ‘" + Startdate + "’, it can be executed. However, when I use a dictionary to call this query and modify it to ‘" + Startdate + "’, it becomes unexecutable and displays the error “Run query: Conversion from char to datetime is a syntax error.”
I’m really out of options unfortunately, I don’t understand why it doesn’t work, you seem to be doing everything correctly.
Quite frustrating, to be fair.
What I would suggest is the following:
Where your sqlQuery variable is defined as follows:
@Irene Thank you very much for your assistance. In general, let me explain what I am trying to accomplish. I need to set the StartDate and EndDate in an Excel file as conditions. When the condition matches with StartDate being equal to Today, it will fetch the SQL query and populate the corresponding syntax. Therefore, I cannot assign the StartDate and EndDate in advance.
But that doesn’t change from how you were doing your process already: you were still setting your StartDate and EndDate parameters at some point, right? And you were using two variables:
I misunderstood your mean earlier. I’m glad to that able to successfully execute the SQL query using the approach you provided. Thank you very much for your assistance and support.