Hi everyone,I had posted requests for help on a SQL query in another thread:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=146536I've tried another approach, and so I was hoping that this approach would better show the joins that seemed to be the lingering question in the old thread. I'll begin by (re)including my report / requirements and then the code - and you can let me know if you need any more information.Thanks!Report requirements: * Create a query / chart to plot the following:All defects, grouped by Fridays, that meet these criteria:Test Phase = "System Testing" or "Production"Status = "New" or "Open"Note on statuses - these are all the available statuses in our project:NewOpenFixedDeferredRejectRetestClosed Query works but does not properly calculate the 'Open' number of defects - the numbers are way too high, I suspect they are pulling in one of the other status categories, but not sure how to verify: SQL code:-- *******************************************************-- Step 3 Summarize by DateSelect distinct date_friday, sum(new_that_week) as "Total New", sum(new_production) as "New Production", sum(was_open) as "Open Defects", sum(new_testing) as "New Testing", sum(was_closed) as defects_closed, sum(defect_existing) as total_defectsfrom (-- Step 2 Check if Defect was Open / New / Closed that week.select date_friday, day_week, date_last_sat , bg_bug_id, bg_detection_date, bg_closing_date, test_phase, defect_existing, bg_status, open_date,(case when bg_detection_date >= date_last_sat and bg_detection_date <= date_friday then 1 else 0 end) as new_that_week,(case when bg_detection_date >= date_last_sat and bg_detection_date <= date_friday and test_phase = 'Pilot Support' then 1 else 0 end)as new_production,(case when bg_detection_date >= date_last_sat and bg_detection_date <= date_friday and test_phase = 'System Test' then 1 else 0 end)as new_testing,(case when bg_closing_date < DATEADD(day,1,date_friday) then 1 else 0 end)as was_closed,(case when bg_status = 'Open' or(open_date < DATEADD(day,1,date_friday) and bg_closing_date >= DATEADD(day,1,date_friday)) then 1 else 0 end) as was_openfrom (--Step 1 get all defects existing during week rangeselect date_friday, day_week, date_last_sat , bg_bug_id, bg_detection_date, bg_closing_date , bg_user_05 as test_phase, 1 as defect_existing, bg_status,open_datefrom (-- Get all Fridays an calculate week rangeselect distinct d_friday as date_friday, DATENAME(weekday,d_friday) AS day_week,DATEADD(day,-6,d_friday) as date_last_satfrom (-- get all datesSELECT au_time, DATEADD(dd,4,DATEADD(wk, DATEDIFF(wk,0,au_time), 0)) AS d_fridayFROM audit_logwhere DATEPART(YEAR, au_time) = '2010'-- end get all dates) results_1-- end get all Fridays) results_2, (select bg_bug_id, open_date, bg_detection_date, bg_closing_date , bg_user_05, bg_statusFrom bug left join (select distinct au_entity_id, max(au_time) as open_datefrom (SELECT au_entity_id, au_action_id , ap_old_value, ap_new_value , au_time FROM Audit_properties, audit_log where au_action_id = ap_action_id and ap_field_name = 'BG_STATUS' and ap_new_value = 'Open' ) aagroup by au_entity_id) dateon bg_bug_id = au_entity_id ) composed_bugWhere bg_detection_date <= results_2.date_friday-- end step 1) results_3-- end step 2) results_4 group by date_friday-- end step 3-- **********************************************