0

For background information: I'm planning to do some reporting in C# with Entity Framework and I need to create a view for each report (at least I believe I do).

I have already found solutions on how to receive the information I need on various pages. Google was of much help, too.

However what I didn't find is how to turn this procedure into a view or something I can use for reporting.

This is my code:

SET @sql = NULL;
SELECT 
    GROUP_CONCAT(DISTINCT
        CONCAT(
            'MAX(IF(r.HoursMonth = ''',
            HoursMonth,
            ''', r.SumOfHoursWorked, NULL)) AS ''',
            HoursMonth, ''''
            )
    ) INTO @sql
FROM (SELECT HoursMonth, SumOfHoursWorked FROM report_HoursPerMonthPerEmployerCode ORDER BY HoursMonth) AS t;

SET @sql = CONCAT('SELECT DISTINCT e.employerName, ', @sql, ' FROM employer AS e LEFT JOIN report_HoursPerMonthPerEmployerName AS r on e.employerName = r.employerName GROUP BY employerName');

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Community
  • 1
  • 1
david1602
  • 61
  • 6

0 Answers0