Date Q?
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Patrick Enlow (VIP)
Does anyone know of a query trick to get the difference between two
dates from two different records from the same field. The date field is
sorted ascending, and the date that is needed to find the difference
always follows as the next record. There is no other criteria to match
up the two records and same field.

Thanks!
Patrick
Reply to this message...
 
    
=?iso-8859-1?q?Katrina=20Illidge?=
here is a quick query i wrote using Northwind:
-----------------------------------
use northwind

DECLARE c CURSOR
FOR
SELECT orderdate
FROM orders
ORDER BY orderdate

DECLARE @dtFirst datetime, @dtNext datetime

OPEN c
FETCH c INTO @dtFirst
WHILE (@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM c INTO @dtNext
PRINT DATEDIFF(dd,@dtFirst,@dtNext)
SET @dtFirst = @dtNext
END

CLOSE c
DEALLOCATE c
GO

------------------------------------

--- Patrick Enlow <Click here to reveal e-mail address> wrote: > Does anyone know of a
query trick to get the difference between two
[Original message clipped]

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Reply to this message...
 
    
Patrick Enlow (VIP)
Thanks! I will give this a shot!

[Original message clipped]

Reply to this message...
 
    
Remas Wojciechowski
Patrick,

you could probably try a subquery ala:

SELECT
DateField
, (SELECT Min(DateField) FROM MyTable t2 WHERE t2.DateField >
t1.DateField)
FROM
MyTable t1

For the second field you'd want to use a flavor of DATEDIFF to meet your
specific requirements.

hth
Remas
http://www.aspalliance.com/remas

----- Original Message -----
From: "Patrick Enlow" <Click here to reveal e-mail address>
To: "ngfx-sqlclient" <Click here to reveal e-mail address>
Sent: Monday, July 15, 2002 9:33 PM
Subject: [ngfx-sqlclient] Date Q?

Does anyone know of a query trick to get the difference between two
dates from two different records from the same field. The date field is
sorted ascending, and the date that is needed to find the difference
always follows as the next record. There is no other criteria to match
up the two records and same field.

Thanks!
Patrick

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
 




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com