I need to convert the following into a pivot output to display AccountID by months but I'm stuck on the format of pivot having not used it before.
Can someone help please? I'm sure it's simple.
SELECT MONTH(MD.DateAdded) AS 'MonthSent', MD.AccountID, A.Organisation, COUNT(MD.MessageDataID) AS 'Messages Sent'
FROM TA_BUSINESS.dbo.tbl_MESSAGES_DATA AS MD WITH (NOLOCK)
LEFT JOIN TA_BUSINESS.dbo.tbl_ACCOUNTS AS A WITH (NOLOCK)
ON MD.AccountID = A.AccountID
(MONTH(MD.DateAdded) BETWEEN 1 AND 3)
AND YEAR(MD.DateAdded) = 2014
AND (MD.MessageTypeID = 1 OR MD.MessageTypeID = 4 OR MD.MessageTypeID = 5)
AND MD.IsMessageIncoming = 0
AND A.ResellerID = 2007
GROUP BY MD.AccountID, A.Organisation, MONTH(MD.DateAdded)
ORDER BY MD.AccountID