Incorrect syntax error in select query

Hi All,
I am reading a column value from excel file and then using the same value in my select statement as input value. I am getting the below error.

error.docx (84.1 KB)

Kindly help.

@Zahid1,

The Query you have mentioned returns ;
SELECT * from table_name where First_Contact_Business_Name in (Max Realty)

whereas - The variable MaxRealty Should come in Quotes inside query

Please try Below - Include a Single Quote in the Query .

“SELECT * from table_name where First_Contact_Business_Name in (’” + strClientName1+ “’)”


Mukesh

Hi @Zahid1,

You’ve used read column and String.Join with separator ,(comma) to concadinate collection elements to form a string,

As I see it…, In your query, var strClientName1 should hold string something like —> 'a','b','c'.
But by using ,(comma) as a separator in String.Join method, you’ll get string —> 'a,b,c' which is wrong,
to achieve the same you should use ',' as separator in String.Join as I shown here —> strClientName = String.Join("','",varClientName) to get string like —> 'a','b','c'

check output of strClientName1 in messageBox and before make sure you change it’s variable type from generic to String.
then use following query.

"SELECT * from table_name where First_Contact_Business_Name in ('" + strClientName1+ "')"

Thanks @mukeshkala & @samir Its working perfectly.

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