I have a table that has fields username, client_num, mon, tues, wed, thurs, fri, sat, sun, thisweek and active. I'm trying to sum the mon-fri grouping by month and client number (and possibly username).I've been trying the following, but the query doesn't seem to execute. I get no errors, but the query never finishes execution (or at least takes extremely long).--declare @client intdeclare @date datetime--set @client = 155;set @date = '9/5/2009';SELECT card.client_num, SUM(m.monday + t.tuesday + w.wednesday + r.thursday + f.friday + s.saturday + d.sunday)FROM cardLEFT JOIN ( SELECT client_num, SUM(mon) AS monday FROM card WHERE MONTH(@date)=MONTH(thisweek) AND active='True' GROUP BY card.client_num) AS m ON card.client_num=m.client_numLEFT JOIN ( SELECT client_num, SUM(tues) AS tuesday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,1,thisweek)) AND active='True' GROUP BY card.client_num) AS t ON card.client_num=t.client_numLEFT JOIN ( SELECT client_num, SUM(wed) AS wednesday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,2,thisweek)) AND active='True' GROUP BY card.client_num) AS w ON card.client_num=w.client_numLEFT JOIN ( SELECT client_num, SUM(thurs) AS thursday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,3,thisweek)) AND active='True' GROUP BY card.client_num) AS r ON card.client_num=w.client_numLEFT JOIN ( SELECT client_num, SUM(fri) AS friday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,4,thisweek)) AND active='True' GROUP BY card.client_num) AS f ON card.client_num=w.client_numLEFT JOIN ( SELECT client_num, SUM(sat) AS saturday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,5,thisweek)) AND active='True' GROUP BY card.client_num) AS s ON card.client_num=w.client_numLEFT JOIN ( SELECT client_num, SUM(sun) AS sunday FROM card WHERE MONTH(@date)=MONTH(DATEADD(DAY,6,thisweek)) AND active='True' GROUP BY card.client_num) AS d ON card.client_num=w.client_numGROUP BY card.client_numORDER BY card.client_num ASC
edit: I've run parts of it and it seems to run as expected for monday-wednesday. On thursday it returns each row in thurs as well as the total, and this is output for each group (and is the same), and the execute time is much slower.For example:I get this when I run without thursdayclient monday tuesday100 10.5 16105 6.5 7...
With Thursday I get:client monday tuesday thursday100 10.5 16 2.5100 10.5 16 1100 10.5 16 3.5105 6.5 7 1105 6.5 7 2.5105 6.5 7 3.5...