Monday, August 20, 2012 5:50 PM
I need help with sql query max(date) in select statement ( using ms sql server 2008 r2)
I have a query that sums up transaction costs for each job and I am trying to add a last transaction date for each of those jobs, ie (max_transaction_date).
I am trying just insert the Max() function into existing code but not getting the results. I could really use so pointers about how to get this done.
If I need to run the max() statement as a separate sub select and join it to transaction sum, no problem. Just need help in getting the latest transaction date for each job to show.
SELECT distinct WAC_JC_COST_DETAIL.Job_Number AS WAC_JOB_NUMBER
, MAX(WAC_JC_COST_DETAIL.Tran_Date_Text) as Max_Tran_Date -- >FYI<Tran_Date_Text is a 'Date' field
,SUM(WAC_JC_COST_DETAIL.Tran_Amount) AS Sum_Tran_Amount
GROUP BY WAC_JC_COST_DETAIL.Job_Number
Best as always,