davecarrera
Technical User
Ver new to SQL and trying to get this right.
I am using Reporting servcies 2000 to try and make a week by week total report.
I have this sql at the moment cobbled together from various websites.
SELECT customer AS Cust,
CASE WHEN dated >= '09/10/06' AND dated <= '09/16/06' THEN (SUM(amount)) ELSE 0 END AS Week0,
CASE WHEN dated >= '09/17/06' AND dated <= '09/23/06' THEN (SUM(amount)) ELSE 0 END AS Week1,
CASE WHEN dated >= '09/24/06' AND dated <= '09/30/06' THEN (SUM(amount)) ELSE 0 END AS Week2,
CASE WHEN dated >= '10/01/06' AND dated <= '10/07/06' THEN (SUM(amount)) ELSE 0 END AS Week3,
ISNULL(
( SELECT customer as cust2,
SUM(Week0) AS [Week of 16/09/06],
SUM(Week1) AS [Week of 23/09/06],
SUM(Week2) AS [Week of 30/09/06],
SUM(Week3) AS [Week of 07/10/06]
FROM table
WHERE (dated >= CONVERT(DATETIME, '2006-09-10 00:00:00', 102)) AND (dated <= CONVERT(DATETIME, '2006-10-07 00:00:00', 102))
GROUP BY customer, dated, kind
HAVING (kind = 'INV') OR
(kind = 'CRN')
),0) AS DETAIL
FROM table
WHERE (dated >= CONVERT(DATETIME, '2006-09-10 00:00:00', 102)) AND (dated <= CONVERT(DATETIME, '2006-10-07 00:00:00', 102))
GROUP BY customer, dated, kind
HAVING (kind = 'INV') OR
(kind = 'CRN')
ORDER BY customer
But all i get is errors saying week0 not a colum.
I maus have something wrong here so i ask for someone who is cleverer than i with sql to have a look a guide me gentley towards an answer.
Many Kind Regards
Dave
I am using Reporting servcies 2000 to try and make a week by week total report.
I have this sql at the moment cobbled together from various websites.
SELECT customer AS Cust,
CASE WHEN dated >= '09/10/06' AND dated <= '09/16/06' THEN (SUM(amount)) ELSE 0 END AS Week0,
CASE WHEN dated >= '09/17/06' AND dated <= '09/23/06' THEN (SUM(amount)) ELSE 0 END AS Week1,
CASE WHEN dated >= '09/24/06' AND dated <= '09/30/06' THEN (SUM(amount)) ELSE 0 END AS Week2,
CASE WHEN dated >= '10/01/06' AND dated <= '10/07/06' THEN (SUM(amount)) ELSE 0 END AS Week3,
ISNULL(
( SELECT customer as cust2,
SUM(Week0) AS [Week of 16/09/06],
SUM(Week1) AS [Week of 23/09/06],
SUM(Week2) AS [Week of 30/09/06],
SUM(Week3) AS [Week of 07/10/06]
FROM table
WHERE (dated >= CONVERT(DATETIME, '2006-09-10 00:00:00', 102)) AND (dated <= CONVERT(DATETIME, '2006-10-07 00:00:00', 102))
GROUP BY customer, dated, kind
HAVING (kind = 'INV') OR
(kind = 'CRN')
),0) AS DETAIL
FROM table
WHERE (dated >= CONVERT(DATETIME, '2006-09-10 00:00:00', 102)) AND (dated <= CONVERT(DATETIME, '2006-10-07 00:00:00', 102))
GROUP BY customer, dated, kind
HAVING (kind = 'INV') OR
(kind = 'CRN')
ORDER BY customer
But all i get is errors saying week0 not a colum.
I maus have something wrong here so i ask for someone who is cleverer than i with sql to have a look a guide me gentley towards an answer.
Many Kind Regards
Dave