Solved

help with query

Posted on 2013-06-06
4
305 Views
Last Modified: 2013-06-06
hi guys
why this query do not work

INSERT INTO suplementos(numdeord)SELECT DISTINCT numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL

error
ambigous column name

tsm
0
Comment
Question by:edo60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 500 total points
ID: 39226334
try:

INSERT INTO
suplementos (numdeord)
SELECT
      DISTINCT
            odc.numdeord
      FROM odc
      LEFT JOIN suplementos
      ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39226343
>ambigous column name
That's because numderord exists in both odc and suplementos tables, and T-SQL doesn't know which one you want to insert, and won't assume for you.

INSERT INTO suplementos(numdeord)SELECT DISTINCT odc.numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL

or

INSERT INTO suplementos(numdeord)SELECT DISTINCT suplementos.numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39226347
You need to specify where you're getting numdeord from:

INSERT INTO suplementos(numdeord)
SELECT DISTINCT odc.numdeord
FROM odc
LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 4

Expert Comment

by:BAKADY
ID: 39226380
Try:

INSERT suplementos ( numdeord )
SELECT odc.numdeord
FROM odc LEFT JOIN suplementos
    ON odc.numdeord = suplementos.numdeord
GROUP BY odc.numdeord
HAVING COUNT( suplementos.numdeord ) = 0

Saludos
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question