Need help with SQL Syntax

Posted on 2007-07-24
Last Modified: 2010-05-19
The following SQL was offerred as an unsolicited suggestion in another question I posted that was answered by someone else.

I am getting an error saying there is an unidentified column 'KT_Group_ID' on the last line of the statement.  I have stared at this for hours and cannot see the problem.  Can anyone help.

            UPDATE dbo.Tbl_KT_Items
               SET Observe_Status_Date = i.Observe_Status_Date
                  ,Observe_Percent_Complete = i.Observe_Percent_Complete
                 , Participate_Status_Date = i.Participate_Status_Date
                 , Participate_Percent_Complete = i.Participate_Percent_Complete
                 , Perform_Status_Date =i.Perform_Status_Date
                 , Perform_Percent_Complete = i.Perform_Percent_Complete
              FROM dbo.Tbl_KT_Items as KTI
             Inner Join (SELECT KTInst.Lookup_To_Tbl_KT_Groups_For_KT_Group
                          FROM Inserted as I
                         Inner Join dbo.Tbl_KT_Instances as KTInst
                            ON I.Lookup_To_Tbl_KT_Instances_For_Instance_ID = KTInst.ID
                           and KTInst.Lookup_To_Tbl_KT_Groups_For_KT_Group > 0
                       ) as I  
                on KTI.KT_Step_Number = I.kt_step_Number
               AND I.Lookup_To_Tbl_KT_Groups_For_KT_Group = KTI.KT_Group_ID
Question by:wsturdev
    LVL 15

    Accepted Solution

    the obvious question is are you 100% sure the column name is exactly KT_Group_ID and is in table Tbl_KT_Items?
    LVL 11

    Expert Comment

    I wonder if calling two join sources 'I' is impacting it?
    >>>FROM Inserted as I
           Inner Join dbo.Tbl_KT_Instances as KTInst
           ON I.Lookup_To_Tbl_KT_Instances_For_Instance_ID = KTInst.ID
           and KTInst.Lookup_To_Tbl_KT_Groups_For_KT_Group > 0
    >>>) as I  

    Sometimes the errors point at the wrong thing.

    LVL 1

    Author Comment

    derekkromm -- that was it!!!

    The author of the code was supposed to use a Declared variable from much farther up in the code.  There was no column called that in the specified table.  IT should have been a reference to @KT_Group_ID.

    Thanks for triggering the brain cells!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    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…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now