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
 Making insert and geting Err on "ON"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

statix
Starting Member

12 Posts

Posted - 02/12/2013 :  10:41:58  Show Profile  Reply with Quote
what's wrong in my query?

INSERT INTO CC
                  (county_id, city_id)
SELECT DISTINCT x1.county_id, x2.city_id
FROM                     datazip AS d  
                               county AS x2 ON d.county = x2.county_name INNER JOIN
                               city AS x2 ON d.city = x2.city_name


James K
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 02/12/2013 :  10:49:04  Show Profile  Reply with Quote
The syntax should be something like this:
INSERT INTO CC
  (
    county_id,
    city_id
  )
SELECT DISTINCT x1.county_id,
       x2.city_id
FROM   datazip AS d 
       INNER JOIN county AS x1 
            ON  d.county = x1.county_name
       INNER JOIN city  AS x2
            ON  d.city = x2.city_name
Go to Top of Page

statix
Starting Member

12 Posts

Posted - 02/12/2013 :  11:28:52  Show Profile  Reply with Quote
thanks worked like a charm!
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 02/12/2013 :  12:19:19  Show Profile  Reply with Quote
Great! glad it helped.
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.06 seconds. Powered By: Snitz Forums 2000