Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 what's wrong in my query ? :\

Author  Topic 

statix
Starting Member

12 Posts

Posted - 2013-01-31 : 18:58:34
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
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2013-01-31 : 19:31:20
[CODE]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??[/CODE]


=================================================
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 - 2013-01-31 : 19:38:39
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

52326 Posts

Posted - 2013-02-01 : 02:57:53
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
   

- Advertisement -