Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET How to select the earliest and latest record of a set of rows based on timestamp and ID Sql server

Posted on 2008-10-08
2
Medium Priority
?
422 Views
Last Modified: 2012-05-05
I have many rows being returned which contain a autonumber, qty, timestamp and foreignKeyID fields...what I need is to get the totalqty of all the rows, and the time difference between the latest timestamp and the earliest timestamp all based on the same foreign key ID

Based on these variables I need to see the totalqty/time difference ...which will give the # of units counted per minute.

I am using VB.Net and Sql Server 2005... I am just a bit fuzzy on the actual grabbing of the earliest & latest timestamp... I could use the AutoNumber field ( Max / Min)  of the table based on the foreign key...but is there a better way...

Any help or insight would be much appreciated...
0
Comment
Question by:nomar2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 192 total points
ID: 22674870
From SQL couldn't you just do:

SELECT COUNT(*) AS Qty, MAX(timestamp) as MaxTime, Min(TimeStamp) as MinTime, ForeignKey
FROM table
GROUP BY ForeignKey

0
 

Author Comment

by:nomar2
ID: 22682090
Perfect....

I changed the code a little but this is what I came up with based on your suggestions...

SELECT     SUM(iquantity) / DATEDIFF(minute, MAX(editeddate), MIN(editedDate)) AS OverCount
FROM         tInvDetail
WHERE     (iInvoiceID = 33202)

This returns the # of items counted per minute
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question