• Slightly different to Lowell's code and I'm not sure which is correct:

    SELECT

    d.TR_STOCKNO,

    d.CT_STOCKSUMMARY,

    d.PH_SUPPLIERCODE,

    su.SU_SUPPLIERNAME,

    d.PH_RAISEDDATE,

    d.TR_DATE,

    d.LASTPO,

    d.LASTVENDOR,

    d.LASTGRN,

    d.Age

    FROM (

    SELECT

    tr.TR_STOCKNO,

    ct.CT_STOCKSUMMARY,

    ph.PH_SUPPLIERCODE,

    --SU_SUPPLIERNAME,

    ph.PH_RAISEDDATE,

    tr.TR_DATE,

    MAX(ph.PH_RAISEDDATE) OVER (PARTITION BY tr.TR_STOCKNO) AS LASTPO,

    MAX(ph.PH_SUPPLIERCODE) OVER (PARTITION BY tr.TR_STOCKNO) AS LASTVENDOR,

    MAX(TR_DATE) OVER (PARTITION BY tr.TR_STOCKNO) AS LASTGRN,

    DATEDIFF(DAY,

    (MAX(ph.PH_RAISEDDATE) OVER (PARTITION BY tr.TR_STOCKNO)),

    (MAX(tr.TR_DATE) OVER (PARTITION BY tr.TR_STOCKNO)))

    As Age

    FROM ST_TRANSACTIONS tr

    INNER JOIN PO_PURCHASEHEADER ph

    ON ph.PH_ORDERNO = tr.TR_PONO

    INNER JOIN ST_COMMODITYTYPE ct

    ON tr.TR_STOCKNO = ct.CT_STOCKNO_P

    WHERE tr.TR_TYPECODE = 'PREC'

    ) d

    INNER JOIN ST_SUPPLIER su

    ON su.SU_SUPPLIERCODE_P = d.PH_SUPPLIERCODE

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden