I am trying to pass a string value to sql query dynamically:
The query is :-
“SELECT distinct user_name,site_name,manager_1,manager_2,description
FROM xxxinternal.xxxtable
where back_group in (”+spList+“)
and main_group in (‘Delhi’,‘Mumbai’,‘Kolkata’)”
and the value for spList is as below, which is an output of another query:-
‘Hyderabad’,‘Pune’,‘Bangalore’
Getting an syntax error as : “String constants must end with double quotes”. Looking for a breakthrough.
Can you please try printing thw query in log message and check…there might be an extra double quote or a missing one…alternately might be the case that it is expecting double quotes in place of single
Also for ease try enclosing table between square brackets
Hi Anil,
I used the same approach with ”+spList+“ and it was successful.
The trick here is the query should be in a single line without a new line , if we are using parameters.
“SELECT distinct user_name,site_name,manager_1,manager_2,description FROM xxxinternal.xxxtable where back_group in (”+spList +“) and main_group in ‘Delhi’,‘Mumbai’,‘Kolkata’)”
I used the same approach with ”+spList+“ and it was successful.
The trick here is the query should be in a single line without a new line , if we are using parameters.
“SELECT distinct user_name,site_name,manager_1,manager_2,description FROM xxxinternal.xxxtable where back_group in (”+spList +“) and main_group in ‘Delhi’,‘Mumbai’,‘Kolkata’)”