I’m using sql server 2008. I’m doing a query which is going to be used by a SSIS.
I have this data on a select:
Master_Code Jan
1 4
2 5
I would like to add a total on the last row like this:
Master_Code Jan
1 4
2 5
Total 9
Is good practice to do this from sql or should I do this total from SSIS?
You can easily do this with a
UNION ALL. The key is that thatmaster_codefield must be the same data type as the stringtotalso you will have to convert it:See SQL Fiddle with Demo
Or you can use
GROUP BY with ROLLUP:See SQL Fiddle with Demo