SQL Qurery help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • solutionsville
    New Member
    • Feb 2008
    • 4

    SQL Qurery help

    I have a table with zipcode, and city in it, and another one with State. I have a form with three fields.

    If I type the zip code, I want to populate the City and State fields of the form.

    Don't know how to write this query.

    Thanks,

    Brian
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by solutionsville
    I have a table with zipcode, and city in it, and another one with State. I have a form with three fields.

    If I type the zip code, I want to populate the City and State fields of the form.

    Don't know how to write this query.

    Thanks,

    Brian
    I'd say this is 90% apps dependent. It depends on what you used for your front-end. It also depends on what kind of connection and data object you used. But this query returns the City and the state based on the zipcode

    Code:
    SELECT YourCityColumn, YourStateColumn from YourZipTable where YourZipCode = 94105
    or

    Code:
    SELECT YourCityColumn, YourStateColumn from YourZipTable where YourZipCode = @ZipCodeOnYourVariable
    My suggestion is for you to build your query dynamically inside your apps before running it.

    -- CK

    Comment

    • sleepydog3
      New Member
      • Jun 2007
      • 7

      #3
      Code:
      SELECT c.city, s.state, s.zipCode FROM table1 s 
      LEFT JOIN table2 c ON s.zipCode = c.city 
      WHERE s.zipCode = '98021'
      [HTML]http://en.wikipedia.or g/wiki/Join_(SQL)[/HTML]

      This should get you on the right path.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        I missed that part. I thought it's all in one table.

        My bad.

        -- CK

        Comment

        Working...