Error in string definition of a SQL Query with variables

Hi,

I’m trying to run the following SQL query with variables (arguments), but even before running it, I get the error that a string must end with a double quote. I tried to insert the double quote in several ways, but I didn’t find sofar the correct way:

"Select
Hot.H_KEY, Hot.H_NAME1, Hot.H_STRASSE, Hot.H_PLZ, Hot.H_ORT, LND.L_LAND
FROM HRSDB.HOTEL Hot inner join hrsdb.laender LND on Hot.l_id = LND.l_id
where
H_NAME1 = "+ in_HotelName + "And H_PLZ = " + in_ZipCode +"And H_STRASSE = "+ in_Address +"And H_ORT = "+ in_City+ "And L_LAND = "+ in_Country

How can I insert the double quote of my SQL statement in order that Studio is happy?

Thanks a lot in advance,
Franz

we assume you had used an assign activity / field box. It is not supporting spanning over multiple lines. Give a try at

"Select " &
 "Hot.H_KEY, Hot.H_NAME1, Hot.H_STRASSE, Hot.H_PLZ, Hot.H_ORT, LND.L_LAND " &
"FROM HRSDB.HOTEL Hot inner join hrsdb.laender LND on Hot.l_id = LND.l_id " &
" where " &
" H_NAME1 = "+ in_HotelName + " And H_PLZ = " + in_ZipCode +" And H_STRASSE = "+ in_Address +" And H_ORT = "+ in_City+ " And L_LAND = "+ in_Country

The problem is not the multi line. I have another long query, with several lines that is running directly without any problem. The problem is the double quote at the end of the string that defines my SQL statement. I tried with a single double quote, a double quote between 2 double quotes, and so on… I’m sure I’m doing something wrong, but I don’t know what…

just show us a screenshot along with the validation message. thanks

Should be there a space before ‘And’?

Cheers

Here the screenshot of the message:

The percentage was just a test… Here another screenshot with another test, but the result is still the same…

image

Try like this

"Select " + _
"Hot.H_KEY, Hot.H_NAME1, Hot.H_STRASSE, Hot.H_PLZ, Hot.H_ORT, LND.L_LAND " + _
"From HRSDB.HOTEL Hot inner Join hrsdb.laender LND On Hot.l_id = LND.l_id " + _
"Where H_NAME1 = “+ var + " And H_PLZ = " + var +” And H_STRASSE = “+ var +” And H_ORT = "+ var + " And L_LAND = " + var

note: I use “var” to avoid the need of declaring all the “in_” arguments

cheers

as mentioned above handling spanning lines

I amended the SQL statement this way, breaking the multiline string in this way:

Now I don’t have any more the error before running the query, but when I run it I receive the following error message:

So, it’s still about the double quotes at the end of the string…

e.g. Hotelname end is missing ’ - just check that all starting ’ also will close

This is the fixed version. I needed to put some extra spaces at the beginning of each piece:

“SELECT " + _
“Hot.H_KEY, Hot.H_NAME1, Hot.H_STRASSE, Hot.H_PLZ, Hot.H_ORT, LND.L_LAND” + _
" From HRSDB.HOTEL Hot inner Join hrsdb.laender LND On Hot.l_id = LND.l_id” + _
" Where " + _
“H_NAME1 = '”+in_HotelName+“‘AND H_STRASSE =’”+ in_Address+“’ AND H_PLZ = “+in_ZipCode+ " AND H_ORT = '”+in_City+”’ AND L_LAND = ‘" +in_Country+"’"

OK, looks like the general issue was indentified and handled. So the topic can be closed by you
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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