I have a function in my .NET application, that needs to do a search of an unknown number of parameters.
for example: select * from tbl where x=1 or x=2 or x=3 or x=4
is it possible to do in .NEt and SQL? how do i go about creating dynamic parameters in .NET (I was thinking doing it with a loop) but then how do i declare them in my stored procedure? does sql have arrays?
please help.
thank you!
You might want to look at table-valued parameters (SQL Server 2008 and up):
http://msdn.microsoft.com/en-us/library/bb510489.aspx
You can pass in a comma seperated list, use a table function to split that out into a table and then use an IN clause. This article goes over doing that.
table function:
Then your stored proc can do this:
Try passing in an XML list as the parameter, then you can work through the items in the XML list with a cursor or something similar