SELECT
LEFT(SUBSTRING(j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1, CHARINDEX('_', j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1) - CHARINDEX('_', j.Journey_Name) - 1), LEN(SUBSTRING(j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1, CHARINDEX('_', j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1) - CHARINDEX('_', j.Journey_Name) - 1)) AS Brand_Name,
j.Journey_Name,
j.Journey_Version,
j.Journey_Status,
COUNT(s.SubscriberKey) AS Email_Sends,
GETDATE() AS Last_Modified,
s.SubscriberKey
FROM
(
SELECT
Journey_Name,
Journey_Version,
Journey_Status
FROM
_Journey
WHERE
DATEPART(month, Last_Modified) = DATEPART(month, DATEADD(month, -1, GETDATE()))
AND DATEPART(year, Last_Modified) = DATEPART(year, DATEADD(month, -1, GETDATE()))
) AS j
LEFT JOIN
(
SELECT
JourneyID,
SubscriberKey
FROM
_Sent
WHERE
DATEPART(month, EventDate) = DATEPART(month, DATEADD(month, -1, GETDATE()))
AND DATEPART(year, EventDate) = DATEPART(year, DATEADD(month, -1, GETDATE()))
) AS s
ON
j.JourneyID = s.JourneyID
GROUP BY
LEFT(SUBSTRING(j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1, CHARINDEX('_', j.Journey_Name, CHARINDEX('_', j.Journey_Name) + 1) - CHARINDEX('_', j.Journey_Name) - 1)),
j.Journey_Name,
j.Journey_Version,
j.Journey_Status,
s.SubscriberKey;
While running above query I am getting error :Unable to create temporary data extension: Field name cannot contain the character ,. Field name cannot contain the character ..