Re: Running totals on a select count statement
From: Steve Kass (skass_at_drew.edu)
Date: 03/11/04
- Next message: Liada: "SQL Server with ASP for navision"
- Previous message: Vishal Parkar: "Re: More help with query"
- In reply to: zack: "Re: Running totals on a select count statement"
- Next in thread: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 11 Mar 2004 00:45:58 -0500
Can you let me know what's wrong with this result? I assume part of the
problem is that comparing dd/mm/yyyy strings doesn't put things in date
order - you should just compare the actual datetime values, or if
Creation_Date is not a datetime column, cast it to datetime for the
comparison. Aside from that, you'll have to give me the source data and
result you want, or I won't be able to tell you how to get it.
SK
zack wrote:
>Steve,
>
>Im almost there but Im running into a problem with things being out of order. Here is what I have so far:
>SELECT convert(Char(10), AR.Creation_Date, 101) AS DateWritten, COUNT(AR.Creation_Date) AS Written,
> (
> Select count(AR2.Creation_Date) from dbo.vw_Nothing AR2
> where convert(Char(10), AR2.Creation_Date, 101) <= convert(Char(10), AR.Creation_Date, 101)
> )
> as RunningTotal
>FROM dbo.vw_Nothing AR
>GROUP BY DATEPART(yy, AR.Creation_Date), DATEPART(mm, AR.Creation_Date), DATEPART(dd, AR.Creation_Date), CONVERT(Char(10), AR.Creation_Date, 101)
>
>returns:
>11/10/2003 1 32
>11/11/2003 4 36
>11/13/2003 1 37
>12/18/2003 1 38
>12/22/2003 1 39
>12/23/2003 6 45
>12/24/2003 2 47
>12/30/2003 3 50
>01/12/2004 9 9
>01/29/2004 3 12
>01/30/2004 1 13
>02/06/2004 1 14
>02/10/2004 3 17
>02/24/2004 2 19
>03/04/2004 11 30
>03/05/2004 1 31
>
>Whats happening is that the ordering is lost in the subquery and I can not specify an order by clause in the sub query. When I order the outside sql correctly the count is then incorrect. Any thoughts????? Possible a different date function.
>
>
- Next message: Liada: "SQL Server with ASP for navision"
- Previous message: Vishal Parkar: "Re: More help with query"
- In reply to: zack: "Re: Running totals on a select count statement"
- Next in thread: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|