Q&A for professional and enthusiast programmers
SELECT 'SELECT CAST(''' + BADGES.NAME + '''AS VARCHAR(50)), COUNT(1) FROM BADGES WHERE BADGES.NAME = ''' + BADGES.NAME + ''' UNION ALL' FROM BADGES GROUP BY BADGES.NAME;