In the follow query I'm trying to use a date in the history table when a request is in 'Complete', 'Complete - Verbally Sign Off', 'Closed' but it does not work because Complete_Date is not a valid column.
How would I do this?
SELECT
h.rid AS ID
, d.date AS Submitted_Date
, d.requestor
, d.analyst
, d.qa
, status, Status
, h.Stat_Time
, h.Stat_Date
, CASE WHEN h.status IN ('Complete', 'Complete - Verbally Sign Off', 'Closed')
THEN stat_date
END AS Complete_Date
, s.Service_Name
, t.Task_Name
, d.description
, d.PMT_Tech AS PMT_Technology
, d.[release_date] AS Release_Date
, d.partner_group
,d.sm
FROM [aid1789].[dbo].[dmt_2] AS d
INNER JOIN [aid1789].[dbo].[dmt_request_history] h on (h.rid = d.id)
INNER JOIN [aid1789].[dbo].[service] s on (d.serviceID = s.id )
INNER JOIN [aid1789].[dbo].[task] t on (d.taskID = t.id )
Where status IN (@status)
and Complete_Date Between @Fromdate and @Todate