Skip to content
Advertisement

Compare items in a SQL column with array

I have a SQL server table where I want to query for items on rows which have a value equal to an item in Array. Here’s my example:

And my array:

So, I want to return from SQL rows matching items in the array. my SQL query should return items where column1 matches an item in the array:

This all in C# by the way. Help will be appreciate.

Advertisement

Answer

You can build an SQL query with an IN(@PARAM) clause, and Join them with String.Join, like this:

The items must be enclosed with ‘ ‘ (single quotes).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement