Again, trying to use a value with the max Close Date

  • UPDATE t
    SET Elig_Flag = P.ELIGIBILITY_FLG
    FROM #TEMP_STP t
    CROSS APPLY (
     SELECT P.ELIGIBILITY_FLG
     FROM [SOLICIT].[GTM_DOC_PROD] P
     INNER JOIN [SOLICIT].[GTM_DOC] d
      ON p.[SOLICITATION_ID] = d.[SOLICITATION_ID]
     WHERE P.[PROD_ID] = t.[prodid]
      AND D.[SUPPLIER_ID] = t.[Site]
         AND D.CLOSE_Date = (SELECT MAX(CLOSE_Date) FROM [SOLICIT].[GTM_DOC])
    ) x

    Results in:  The multi-part identifier "P.ELIGIBILITY_FLG" could not be bound.

    I need to learn how  to do this type of logic all the time and get inside out every time I try.
    Here, in this case, i want the Eligiblity_Flag for the record with the Max Close_Date.
    The Eligibility_Flag is in the PROD table and the CLOSE_DATE is in the DOC_PROD

    thanks again for the help

  • jeffshelix - Monday, February 19, 2018 12:22 PM

    UPDATE t
    SET Elig_Flag = P.ELIGIBILITY_FLG
    FROM #TEMP_STP t
    CROSS APPLY (
     SELECT P.ELIGIBILITY_FLG
     FROM [SOLICIT].[GTM_DOC_PROD] P
     INNER JOIN [SOLICIT].[GTM_DOC] d
      ON p.[SOLICITATION_ID] = d.[SOLICITATION_ID]
     WHERE P.[PROD_ID] = t.[prodid]
      AND D.[SUPPLIER_ID] = t.[Site]
         AND D.CLOSE_Date = (SELECT MAX(CLOSE_Date) FROM [SOLICIT].[GTM_DOC])
    ) x

    Results in:  The multi-part identifier "P.ELIGIBILITY_FLG" could not be bound.

    I need to learn how  to do this type of logic all the time and get inside out every time I try.
    Here, in this case, i want the Eligiblity_Flag for the record with the Max Close_Date.
    The Eligibility_Flag is in the PROD table and the CLOSE_DATE is in the DOC_PROD

    thanks again for the help

    The scope of the "P" alias is within the CROSS APPLY.  You cannot reference it outside of the CROSS APPLY.  To reference any columns returned by the CROSS APPLY, you would need to use the alias created for the CROSS APPLY--in this case "x".  So it would be x.ELEGIBILITY_FLG.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • jeffshelix - Monday, February 19, 2018 12:22 PM

    UPDATE t
    SET Elig_Flag = P.ELIGIBILITY_FLG
    FROM #TEMP_STP t
    CROSS APPLY (
     SELECT P.ELIGIBILITY_FLG
     FROM [SOLICIT].[GTM_DOC_PROD] P
     INNER JOIN [SOLICIT].[GTM_DOC] d
      ON p.[SOLICITATION_ID] = d.[SOLICITATION_ID]
     WHERE P.[PROD_ID] = t.[prodid]
      AND D.[SUPPLIER_ID] = t.[Site]
         AND D.CLOSE_Date = (SELECT MAX(CLOSE_Date) FROM [SOLICIT].[GTM_DOC])
    ) x

    Results in:  The multi-part identifier "P.ELIGIBILITY_FLG" could not be bound.

    I need to learn how  to do this type of logic all the time and get inside out every time I try.
    Here, in this case, i want the Eligiblity_Flag for the record with the Max Close_Date.
    The Eligibility_Flag is in the PROD table and the CLOSE_DATE is in the DOC_PROD

    thanks again for the help

    UPDATE t
    SET Elig_Flag = x.ELIGIBILITY_FLAG
    ...

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thanks SO much you guys.
    Drew, thanks for an English language explanation.
    I wll give due credit when i cascade to my coworkers, to you and SSC.

  • jeffshelix - Monday, February 19, 2018 1:54 PM

    Thanks SO much you guys.
    Drew, thanks for an English language explanation.
    I wll give due credit when i cascade to my coworkers, to you and SSC.

    Nice to see.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply