SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 what's wrong in my query ? :\
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

statix
Starting Member

12 Posts

Posted - 01/31/2013 :  18:58:34  Show Profile  Reply with Quote
i try to normal few tables database i hope this code isnt complete mess im not brilliant with sql so dont be harsh with the comments..

SELECT DISTINCT state.state_id , county.county_id , city.city_id

FROM state,county,city,datazip

WHERE state.state_name=datazip AND county.county_name=datazip.county_name city.city_name=datazip.city_name

INTO state county city

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1600 Posts

Posted - 01/31/2013 :  19:31:20  Show Profile  Reply with Quote
SELECT DISTINCT state.state_id , county.county_id , city.city_id
FROM state,county,city,datazip
WHERE state.state_name=datazip Missing .column name AND county.county_name=datazip.county_name Missing AND city.city_name=datazip.city_name
INTO state county city -- Not sure what you are trying to do here. Assign into variables??



=================================================
There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber
Go to Top of Page

statix
Starting Member

12 Posts

Posted - 01/31/2013 :  19:38:39  Show Profile  Reply with Quote
here i fixed it abit while refreshing this page

SELECT DISTINCT states.state_id, county.county_id, city.city_id
FROM     states CROSS JOIN
                  county CROSS JOIN
                  city
WHERE  (county.county_name = datazip.county) AND (city.city_name = datazip.city) AND (states.state_name = datazip.state)

but i still got errors with datazip.state its says "the multi-part identifier "datazip.city" could not be bound

thanks in advance for any kind of help...!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 02/01/2013 :  02:57:53  Show Profile  Reply with Quote
i think what you need is this

SELECT DISTINCT s.state_id , c.county_id , ct.city_id
FROM datazip d
INNER JOIN state s
ON s.state_name= d.state
INNER JOIN county c
ON c.county_name = d.county
INNER JOIN city ct
ON ct.city_name  = d.city


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000