Fine tune some SQL called multiple times
Posted
by Carl
on Stack Overflow
See other posts from Stack Overflow
or by Carl
Published on 2010-06-11T14:44:54Z
Indexed on
2010/06/11
15:02 UTC
Read the original article
Hit count: 511
Hi all, I currently have an SQL query which is currently called multiple times like this (pseudo code):
foreach(KeyValuePair kvp in someMapList)
{
select col1 from table where col2 = kvp.key and col3 = kvp.value;
//do some processing on the returned value
}
The above could obviously call the database a large number of times if it is a big list of pairs.
Can anyone think of a more efficient piece of SQL which could essentially return a list of specific values based on a list of two unique pieces of information so that the processing can be done in bulk? One obvious one would be to build up a big piece of SQL with ORs but this would probably be quite inefficient?
Thanks
Carl
© Stack Overflow or respective owner