Answer the question
In order to leave comments, you need to log in
How to correctly pass an array as a parameter to a SQL query?
We have such a request.
SQLname = "SELECT name FROM dbo.table WHERE id IN("+String.Join(",", items.ToArray())+");";
using (var comm = new SqlCommand(SQLname, conn, null))
{
using (var reader = comm.ExecuteReader())
{
while (reader.Read())
{
}
}
}
Answer the question
In order to leave comments, you need to log in
Not the newest article, but nevertheless: Tests of methods for passing list variables to storage... .
I think through xml the parameter will be the easiest way. In procedure you will make join.
something like:
create procedure p(
@ids xml
)
begin
select name
from
dbo.table
inner join @ids.nodes('/items/item') root(items)
on id = items.value('(text())[1]', 'int')
end
<items>
<item>1</item>
...
<item>1000</item>
</items>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question