I'm trying to build a view for reporting purposes and am having trouble flattening results to display what would normally multiple rows into a single row, by combining a few values into columns. Each organization has two administrators, and would like to display them both in the same row. Query is as follows:
SELECT dbo.Organization.OrganizationName,
CASE
WHEN (dbo.OrganizationUser.AdminOrder = 1)
THEN dbo.OrganizationUser.UserID
ELSE ''
END AS Admin1,
CASE
WHEN (dbo.OrganizationUser.AdminOrder = 2)
THEN dbo.OrganizationUser.UserID
ELSE ''
END AS Admin2
FROM dbo.Organization
INNER JOIN dbo.OrganizationUser
ON dbo.OrganizationUser.OrganizationId = dbo.Organization.OrganizationId
WHERE dbo.OrganizationUser.UserType = 'ADMIN'
Problem is, I get 2 rows that look like
Organization1 - User1 - <empty>
Organization1 - <empty> - User2
I cannot get the rows to consolidate.