A family of Microsoft relational database management systems designed for ease of use.
Isn't that what the Pivot keyword is for?
Better to ask in a SQL Server forum. This one is about the Microsoft Access database product.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I'm using SQL Server 2012. The result of my query below creates two rows for each site. I would like to rollup the rows to show results on one row. However my GROUP BY statement with the column name Site is not being recognized. I'm receiving an error; MSG 207, Invalid column name 'Site'
Example
Current result:
Active Construction
Denver 2 0
Denver 0 2
Would like to see:
Denver 2 2
I tried using GROUP BY but SQL is not recognizing my column heading called Site (created by case statement). I need another person to look at this and show me where I'm going wrong.
Thank you in advance for your help!
Here is my code
SELECT
PersonDataID,
FirstName,
LastName,
PersonEmail,
SignMarkedBy,
DocumentType,
SignedDate,
DocumentSignMedium,
CASE
'denver123' then 'Denver'
'utah456' then 'Utah'
'sandeigo678' then 'SanDiego'
'-1' then 'No Site Associated'
Else LEFT(Location.LocationName,CHARINDEX('-',Location.LocationName+'-')-1)
End as Site,
dbo.Company.CompanyName
FROM dbo.Status INNER JOIN PersonData on PersonData.PersonId = Status.PersonDataID
INNER JOIN dbo.Company on Person.CompanyId = Company.CompanyId
RIGHT OUTER JOIN Location on Status.LocationID = Location.LocationId
Where cast(SignedDate as date) BETWEEN '01/01/2016' and '01/23/2017'
GROUP BY Site
Order BY Site
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Isn't that what the Pivot keyword is for?
Better to ask in a SQL Server forum. This one is about the Microsoft Access database product.