Solved

help with query

Posted on 2013-06-06
4
300 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now