Obviously you need to be able to pass the equivalent of a a two-column table to your stored procedure. There are two (or may be more) different approaches to doing this. See a discussion on this blog (not all of them may be applicable to you because it discusses sharing data between stored procedures). You MAY be able to use the XML method or table valued parameters.If you want to use the XML method, compose the key-value pairs into an XML fragment, for example, like the one shown below:<kvpairs> <kv> <k>1</k> <v>Smith</v> </kv> <kv> <k>2</k> <v>Jones</v> </kv> <kv> <k>3</k> <v>Murray</v> </kv></kvpairs>
Now pass that to a stored procedure and use it like this:SELECT anotherfield FROM table_ t1 INNER JOIN ( SELECT c1.value('k[1]','int') AS [Key], c1.value('v[1]','varchar(64)') AS [Value] FROM @xmlparam.nodes('kvpairs') T(c) CROSS APPLY c.nodes('kv') T1(c1) ) t2 ON t2.[Key] = t1.key1 AND t2.[Value] = t2.key2