I would like to achieve
SELECT @param1, @param2, @param3, t.field1, sum(t.amount)
FROM table t
WHERE t.field 2 IS NOT NULL AND
t.field3ID = '12345'
GROUP BY @param1, @param2, @param3
What is the best approach? Is building dynamic SQL is the way to go?
Dynamic SQL is the only way to go here. However, what kind of table do you have where you have a bunch of optional grouping columns?