Home Forums SQL Server 2008 SQL Server Newbies Coding Counts and Subtotals by day, location and grand totals in T-SQL RE: Coding Counts and Subtotals by day, location and grand totals in T-SQL

  • Randy:

    For my purposes now I just need to generate the results in the standard MS 2005 Management Studio grid. I just need to show the detail data and then the 3 counts/sum/subtotals similar to the output below.

    Show total number of loads (count of rail cars) per day (group by Date Released);

    Sum of Net Tons per day (grouped by Date Released)

    Then sum of the total number of loads (rail cars) by Location (grouped by location);

    Sum of Net Tons by Location (grouped by location).

    Then Grand Totals (Sum of counts of all Loads [rail cars]) and Sum of Net Tons of all Locations [running total???]

    Ticket Number SP_Description CarNumber Product Product_Description DateReleased NetTons

    Claremont, NH

    159026 Claremont, NH AEX12609 BIC Bulk Ice Control Salt 12/18/2013 99.65

    159027 Claremont, NH GNWR5050 BIC Bulk Ice Control Salt 12/18/2013 104.00

    159028 Claremont, NH AEX19091 BIC Bulk Ice Control Salt 12/18/2013 100.03

    Daily Loads: 3 Daily Tons: 303.68

    159220 Claremont, NH AEX16390 BIC Bulk Ice Control Salt 12/20/2013 99.97

    159222 Claremont, NH AEX11529 BIC Bulk Ice Control Salt 12/20/2013 100.00

    Daily Loads: 2 Daily Tons: 199.97

    Location Loads Total: 5 Location Total Tons: 503.65