0

Can anyone tell me why this throws an error?

WITH date_diffs AS 
(
   SELECT
       ctd_item_id,
       ctd_assigned_to,
       DATEDIFF(d, ctd_assigned_date, ctd_review_completed_date) AS DATE_DIFF,
       ROW_NUMBER() OVER (PARTITION BY ctd_item_id ORDER BY date_diff DESC) AS RN 
   FROM
       irt_item_tracking_detail_tbl
)
SELECT
    * 
FROM
    date_diffs 
WHERE
    date_diffs.rn = 1

Error is

Invalid column name 'date_diff'

Can it not be created within the SELECT statement in the WITH?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
traggatmot
  • 1,423
  • 5
  • 26
  • 51

0 Answers0