doing it in the code itself, in the environment i work in normally, would mean moving all the data into memory on the machine where the code executes, rather than manipulating it on the DB server where it already is, so for that reason id use a stored procedure
Anyway, in this particular instance its just for a report, so only needs to be run directly in SQL anyway, so without a doubt is the best way of doing so.