Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7901223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:09:59+00:00 2026-06-03T09:09:59+00:00

(Using SQL Server 2008) I could easily get this to work if I built

  • 0

(Using SQL Server 2008) I could easily get this to work if I built a view, and then a query on the view, but I want to perform this in one SQL query. I have a table that contains two columns (DeliveredDate (DateTime), Delivered (Varchar)). I am first converting DeliveredDate to Date only, and then grouping by Date. At the same time I am performing a Count on Delivered (column is either YES or NULL). Here is what I use to accomplish this portion:

  SELECT CAST([DeliveredDate] As Date),
         COUNT([Delivered])
  FROM [TableName]
  GROUP BY CAST([DeliveredDate] As Date)
  ORDER BY CAST([DeliveredDate] As Date)

As an output, I get something like:

DeliveredDate  |  Delivered
 2012-04-24          10
 2012-04-25         500
 2012-04-26         422
 2012-04-27          33

What I’m looking for is something like this:

DeliveredDate  |  Delivered  |  RunningTotal
 2012-04-24          10            10
 2012-04-25         500           510
 2012-04-26         422           932
 2012-04-27          33           965

I’ve tried various examples I’ve seen out there, but none seem to match this scenario of performing a Count and a RunningTotal on said Count.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:10:01+00:00Added an answer on June 3, 2026 at 9:10 am

    I’m not sure if a CTE counts as a view but this will work in SQL 2005+ which Does Not Support ordered OVER clauses for SUM,

    WITH cte (DeliveredDate, Delivered)
         AS (SELECT Cast([DeliveredDate] AS DATE) DeliveredDate, 
                    Count([Delivered]) Delivered 
             FROM   [TableName] 
             GROUP  BY Cast([DeliveredDate] AS DATE)) 
    SELECT d1.delivereddate, 
           d1.delivered, 
           Sum(d2.Delivered) RunningTotal 
    FROM   cte d1 
           LEFT JOIN cte d2 
             ON d1.delivereddate >= d2.DeliveredDate 
    GROUP  BY d1.delivereddate, 
              d1.delivered 
    ORDER BY d1.delivereddate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2008. This is a really junior question and I could really
Using SQL Server 2008, but could relate to other databases as well probably. If
I am using SQL Server 2008 Enterprise version. I want to know if I
I'm trying to delete a Maintenance Plan JOB using SQL Server 2008 but keep
This could easily be done using code, but I wondered if it could be
I am using sql server 2008 and I'm trying to build a query for
I am using SQL Server 2008 r2. Did the following steps. But it does
Using SQL Server 2008, I want to calculate the timespan, in seconds, that has
Using SQL Server 2008, is there a way to allow inserts to a table
using : SQL Server 2008 R2, Entityframework 4.3.1 my scenario : I read my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.