Returning partial address matches and mismatch position using L2S or SQL

Posted by peter3 on Stack Overflow See other posts from Stack Overflow or by peter3
Published on 2010-03-02T17:33:07Z Indexed on 2010/03/18 19:21 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

I need to implement a method that takes an address split up into individual parts and returns any matching items from an address table. If no matches are found, I want to be able to return a value indicating where it failed. Each input param has a corresponding field in the table.

The signature would look something like this:

List<Address> MatchAddress(string zipCode, string streetName, string houseNumber, string houseLetter, string floor, string appartmentNo, out int mismatchPosition)
{
  // return matching addresses
  // if none found, return the position where it stopped matching
  // zipCode is position 0, appartmentNo is position 5
  //
  // an empty param value indicates "don't check"
}

I know I can construct the method such that I start with all the parameters, execute the query and then remove param by param (from the right side) until either a match is found or I run out of parameters, but can I construct a query that is more effective than that, i.e minimizing the number of calls to the db, maybe even as a single call?

© Stack Overflow or respective owner

Related posts about multiple-matches

Related posts about c#