CREATE TABLE #Email
(
FKGUID UNIQUEIDENTIFIER,
EmailAddress VARCHAR(2500)
)
CREATE TABLE #EmailAddressTable
(
EmailAddress VARCHAR(2500),
IsDefault INT DEFAULT ( 0 ),
FKGUID UNIQUEIDENTIFIER
)
INSERT #EmailAddressTable ( EmailAddress, FKGUID )
SELECT EmailAddress ,
EmployeeGUID
FROM dbo.Employee
INSERT #Email
SELECT fkGUId,
SUBSTRING(( SELECT ',' + s.EmailAddress
FROM #EmailAddressTable s
WHERE ISNULL(s.EmailAddress, '') != ''
AND a.FKGUID = s.FKGUID
ORDER BY s.EmailAddress
FOR
XML PATH('')
), 2, 200000)
FROM #EmailAddressTable a
WHERE ISNULL(a.EmailAddress, '') != ''
GROUP BY a.FKGUID
The temp table #Email contains all the email addresses of each employee.
No comments:
Post a Comment