[Solved] SQL Multiple count on same row with dynamic column
Since you are using SQL Server then you can implement the PIVOT function and if you have an unknown number of period values, then you will need to use dynamic SQL: DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX) select @cols = STUFF((SELECT distinct ‘,’ + QUOTENAME(‘PeriodId’+cast(periodid as varchar(10))) from Periods FOR XML PATH(”), TYPE ).value(‘.’, … Read more