How to pass string value as parameter in sql squer?

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

instead of
”+spList+“
try
“+Chr(34)+spList+Chr(34)+”

Hi @vidyasak

Please check this tutorial

Regards

@vidyasak

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

Cheers

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’)”

1 Like

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’)”

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