Execute query with Select query with parameters

Ex query: Select col1,col12 from Table where col1 in (‘test1’,‘test2’,‘test3’)
when I tried to pass a single value(‘test1’) as a string it’s worked fine. but when I pass multiple strings to the parameter like (‘test1,test2,test3’) for some reason it’s considering as a single string.
is there a way to pass multiple strings ‘IN’ queries?

Parameter: str_Parameter='test1,test2,test3"
Query: Select col1,col12 from Table where col1 in (@str_Parameter)

Could some help me with the above query syntax?

It’s considered a single string because it IS a single string.

This is a single string: “test1, test2, test3”

This is three strings: “test1”, “test2”, “test3”

Hi @rkrama04 ,

Try “’”+test1 + “’” + “,” + “’” + test2 + “’” + “,” + “’” +test3 +"’"

image

1 Like

In case you are reffering to MS SQL/T-SQL then using parameter in IN clause is not supported.

See also How do I use a variable in an IN clause? | SQL Studies

Cheers

And also here:

Cheers

@rkrama04 , Is it worked ?