Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Red face Unanswered: Ambiguous Column Name

    Hi,

    I have a table named ORDER_WFPLAN_TEMPLATE, and I have written a query to fetch the details from that table as below.

    SELECT OW1.PROJECT_ID,OW1.DESCRIPTION , OW1.SL_NO
    FROM ORDER_WFPLAN_TEMPLATE OW1
    INNER JOIN (SELECT PROJECT_ID,DESCRIPTION FROM ORDER_WFPLAN_TEMPLATE
    GROUP BY PROJECT_ID,DESCRIPTION
    HAVING COUNT(DESCRIPTION)>1) OW2
    ON OW2.PROJECT_ID = OW1.PROJECT_ID AND OW2.DESCRIPTION = OW1.DESCRIPTION
    ORDER BY PROJECT_ID, DESCRIPTION


    This query is working fine in some Databases. But some Databases throw an error

    Msg 209, Level 16, State 1, Line 7
    Ambiguous column name 'PROJECT_ID'.
    Msg 209, Level 16, State 1, Line 7
    Ambiguous column name 'DESCRIPTION'.


    Does this got anything to do with Server versions? One thing I noticed was One of the DB was restored from 2000 to 2005.

    Can somebody help me out to solve this issue. Thanks in advance

    Regards,
    MoonWalker

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You need to qualify all your columns!
    Code:
    ORDER BY OW1.PROJECT_ID, OW1.DESCRIPTION
    George
    Home | Blog

  3. #3
    Join Date
    Jan 2009
    Posts
    2
    Thank you George for your quick reply,

    I got that solution, but my doubt is why it's not showing the error in all the DBs.

    We were not able to simulate this bug in our Testing DB or in the Development DB. But it got hit "all ends up" from the site.

    Does it got anything to do with the DB Versions?

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    In 2k (IIRC) you didn't need to fully qualify as it assumed you referred to the columns in the SELECT list. In 2k5, this changed. It could be versions, it could be compatibility levels that are causing this.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Order by 1,2 still works in 2 k8.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •