I'm stuck with this, please provide some guidance.
I have 3 column which I am grouping by SalesDateTime
using DATEPART
So far everything works great but I would like to add a 3rd column that will contain the concatenated product description e.i Good product 1,Good product 2,Good product 3
Here is my script
CREATE TABLE #Sales
(
Name VARCHAR (100),
SalesDateTime DATETIME,
Description VARCHAR (100)
)
GO
INSERT INTO #Sales
SELECT 'Product1',
'2012-04-01 00:00:00.000',
'Good product 1'
UNION ALL
SELECT 'Product2',
'2012-04-02 00:00:00.000',
'Good product 2'
UNION ALL
SELECT 'Product3',
'2012-04-02 00:00:00.000',
'Good product 3'
UNION ALL
SELECT 'Product4',
'2012-04-03 00:00:00.000',
'Good product 4'
UNION ALL
SELECT 'Product5',
'2012-04-03 00:00:00.000',
'Good product 5'
UNION ALL
SELECT 'Product1',
'2012-04-30 00:00:00.000',
'Good product 6'
UNION ALL
SELECT 'Product1',
'2012-04-30 00:00:00.000',
'Good product 7'
UNION ALL
SELECT 'Product1',
'2012-05-02 00:00:00.000',
'Good product 8'
UNION ALL
SELECT 'Product5',
'2012-05-02 00:00:00.000',
'Good product 9'
UNION ALL
SELECT 'Product5',
'2012-05-02 00:00:00.000',
'Good product 10'
GO
--GROUP BY DAY of Year
SELECT count(*) AS SalesCount, DATEPART(dayofyear,SalesDateTime) Day
FROM #Sales
GROUP BY DATEPART(dayofyear,SalesDateTime)
GO
DROP TABLE #Sales