.NETGURU
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...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification