Hi all,every day our financial controllers are creating a report with the sum of revenue per country for the previous day. This list of countries is usually pretty static but every now and then there are new countries popping up that hasn't generated revenue before. Is it possible to generate a pivot statement that has a dynamic list of countries?? The following is what I'm using today but as you can see UK is not appearing for the 12th even though it's data is in the table->DECLARE @table table ( CountryCode char(2), Revenue decimal(8, 2), RevenueDate datetime)INSERT INTO @tableSELECT 'NO', 51478, '2008-11-11' UNION ALL SELECT 'SE', 478, '2008-11-11' UNION ALLSELECT 'DK', 2154, '2008-11-11' UNION ALL SELECT 'NO', 51478, '2008-11-12' UNION ALLSELECT 'FI', 74123, '2008-11-12' UNION ALL SELECT 'UK', 124, '2008-11-12' UNION ALLSELECT 'SE', 8741, '2008-11-12'SELECT * FROM @tableSELECT [SE] = [SE], [NO] = [NO], [FI] = [FI], [DK] = [DK]FROM ( SELECT CountryCode, Revenue = SUM(Revenue) FROM @table-- WHERE RevenueDate = '2008-11-11' WHERE RevenueDate = '2008-11-12' GROUP BY CountryCode ) AS aPIVOT ( SUM(Revenue) FOR CountryCode IN ([SE], [NO], [FI], [DK]) ) AS b
How can I solve this without adding all country codes to my query...?- Lumbago