When using RUN QUERY, the error message "Invalid column name '統計終止日期'." and "Invalid column name '統計起始日期'

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 ‘統計起始日期’.



Is it not possible to use Chinese characters as variables in the RUN QUERY activity?

Hi!

You need to add @ before the variable name you want to replace in the query.
Example
I have set up a parameter named “startdate”

“Select * From Table where SomeDate > ‘@startdate’”

Thank you for the answer,but I tried to add @ before variables then output error “Run query: Variable ‘@’ must be declared.”

Could you try with a different variable name?

https://docs.uipath.com/activities/other/latest/user-guide/execute-query

I test different variable name still output “Running query: variable ‘@Startdate@Enddate



must be declared.”

Hi!

I think I see the problem.

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.

I tried to convert my imput arguments into type datetime but still output The variable @Startdate needs to be declared.


HI @tiffany840318

You can refer to this SQL writing method.

"select * from table_name where startdate = '" + Startdate + "' and enddate = '" + Enddate + "'" 

You spelled “dete” with an E instead of “date”:

@shan.huang Thans for answer.


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.”

The correct syntax is with the @ symbol before the parameter name, for example:

image

And with parameters defined as follows (I used hard-coded values in the screenshot, but it’s OK to use variables instead, obviously):

It seems like you had a typo in your parameter definition, please refer to my earlier post:

@Irene Thanks for answer.I refer to your suggestion.But still not work.

Ok, thanks for the confirmation!
Does it work if you remove entirely the condition on the dates?

@Irene If I directly use the date without using a variable, it can be executed.

I’m really out of options unfortunately, I don’t understand why it doesn’t work, you seem to be doing everything correctly. :face_with_diagonal_mouth:
Quite frustrating, to be fair.

What I would suggest is the following:

image

Where your sqlQuery variable is defined as follows:

Be careful with the quotation marks you must have single and double quotation marks in the correct order):

BETWEEN '" + startDate + "' And '" + endDate + "'"

The argument of your Run Query activity will be just the variable, and the params will be empty:

@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. :smiling_face_with_tear:

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:

Instead of assigning those two variables as parameters, you’ll have to use them in the Assign statement, right before executing the query.

I don’t understand why this approach wouldn’t work in your case. Can you explain this more in detail please? Thanks :slight_smile:

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.

1 Like

I’m glad it worked!! :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.