By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

SQL Qurery help

P: 4
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
Feb 27 '08 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
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

Expand|Select|Wrap|Line Numbers
  1. SELECT YourCityColumn, YourStateColumn from YourZipTable where YourZipCode = 94105
  2.  
or

Expand|Select|Wrap|Line Numbers
  1. SELECT YourCityColumn, YourStateColumn from YourZipTable where YourZipCode = @ZipCodeOnYourVariable
  2.  
My suggestion is for you to build your query dynamically inside your apps before running it.

-- CK
Feb 27 '08 #2

sleepydog3
P: 7
Expand|Select|Wrap|Line Numbers
  1. SELECT c.city, s.state, s.zipCode FROM table1 s 
  2. LEFT JOIN table2 c ON s.zipCode = c.city 
  3. WHERE s.zipCode = '98021'
  4.  
[HTML]http://en.wikipedia.org/wiki/Join_(SQL)[/HTML]

This should get you on the right path.
Feb 27 '08 #3

ck9663
Expert 2.5K+
P: 2,878
I missed that part. I thought it's all in one table.

My bad.

-- CK
Feb 27 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.