Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:32:45+00:00 2026-05-13T23:32:45+00:00

I need to implement a method that takes an address split up into individual

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:32:45+00:00Added an answer on May 13, 2026 at 11:32 pm

    I think you could get a solution in one query using case statements and some nested queries, but before I go there, I’m not sure I follow what you’re trying to accomplish. Assume the following sample data set:

    ID   House_Number    Street_Name   Zip_Code
    =============================================
    1            3012            Elm      10010
    2             412            9th      10010
    3             412           Main      90210
    4             710           Main      60606
    

    Also assume the following method call, passing in a zip, name and house number:

    MatchAddress('10010', 'Main', '710')
    

    What would you want to get back in this case? Your signature has a single out variable for the mismatch position, but this example would partially match all four of the records involved on at least one element. What would you want to return for record 1, for instance, where there’s a match on zip code, but not on the house_number or street_name attributes?

    ======================================

    OK, saw your comment. Here’s a query that I think is on the right path for you. The WHERE clause is a series of ORs that return any record that matches on at least one of the criteria. Then the case statement looks to see where they’re not equal to the passed in value. Obviously the least specific match is subjective, but you could re-order the case statement to put the desired match criteria in the order you want. I had this working on a MySQL db here.

    SELECT address.*, CASE 
        WHEN zip_code <> '10010' THEN 'No match on Zip'
        WHEN street_name <> 'Elm' THEN 'No match on Street Name'
        WHEN house_number <> '29' THEN 'No match on House Number'
        ELSE 'Match on all elements'
      END AS zip_match
    from address
    where zip_code = '10010'
    OR street_name = 'Elm'
    OR house_number = '29'
    

    I’ve made it return some pretty wordy statements for clarity here, but you could obviously have it return a number code or whatever makes sense for you. This also doesn’t take into account issues like case sensitivity. As it’s written, it’s looking for precise case matching too. Depending on your db environment or how you’re data is stored, you may need to address that if that’s not what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a generic method that takes a tuple and returns a
I need to implement a call to a method that I have in my
I need a method that takes an Action (or a Func), but the Action
I need to implement a method for non-linear interpolation between values, ease-in, ease-out, general
I have an iPhone application and I need to implement the following method: +(UITextView
I need to implement in my class Invoke() method with the same behavior as
This is a question about how to implement the equals method when I need
I have a method that takes in an id, a start date, and and
I want create a rest method(http put) that takes a list of string as
I need to implement a pool of Sessions that are returned by an external

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.