Writing a good sql script is an art, i don't know what is your original intention to do such a script,
Anyway i will suggest you way better and concise
DECLARE @mode INT;
SET @mode = 0;
DECLARE @sql nvarchar(4000)
SET @sql = ' ' + char(10)
+ 'SELECT ' + char(10)
+ ' '+ CASE WHEN @mode=0 THEN +'t.Column1,COUNT(t.Column2) AS Column2 ' + char(10)
ELSE + 'TOP 1 t.Column1, COUNT(t.Column2) AS Column2 ' + char(10) END
+ ' ' + char(10)
+ ' ' + char(10)
+ 'FROM Table1 t ' + char(10)
+ '--Where some list of parameters ' + char(10)
+ 'GROUP BY t.Column1,t.Column2 ' + char(10)
+ ''
EXEC(@sql)
but when you use a top operator always use the order by clause otherwise the output will be unpredictable
hope you got it :) happy coding