Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2011, 11:10 AM
Registered User
 
Join Date: Apr 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default Help with sql statment

Hello, I thought I had this licked but am stuck on the last bit.

I am using asp.net 2.0 with a sql database using sql server 2005 and have a table with 4 columns and am trying to make a filter for a pneumatic tube delivery system that is used where I work.

The table looks like this:

ID(key) TubeDestination TimeSent ContainsItems
1-------- 88 -------------20:00 -----yes
2-------- 88 -------------21:00 -----no
3-------- 88 -------------22:00 -----yes
4------- 100 -------------20:00 -----yes
5------- 100 -------------21:00 -----yes
6--------100 -------------22:00 -----yes
7--------150 -------------21:00 -----yes
8--------150--------------23:00-----yes

I'd like to display the most recent tube destination and time sent for each tube station but only if it has been more than one hour since a tube has been sent to a location

For the above table if it was currently 23:30 I would hope for the below return:

TubeDestination TimeSent
--88------------- 22:00
--100------------ 22:00

I'm thought the following was right but then realized it will show the most recent tube destination and time that is greater than one hour but will show a that destination that was sent more than an hour ago even if a more recent tube was sent within the past hour.

SELECT TubeDestination, MAX(TimeSent) AS TimeSent
FROM Table1
WHERE TimeSent < dateadd(hh,-1,getdate())
GROUP BY TubeDestination

as an example...the 88 and 100 are right but the 150 is showing up and I don't want it to at all since there was a more recent tube sent at 2300.

TubeDestination TimeSent
--88------------- 22:00
--100------------ 22:00
--150-------------21:00

Every nested query I use seems to end up using two columns which is a no-no. If anyone has some ideas or a solution I'd love the help. Thanks Dan
 
Old May 6th, 2011, 01:13 PM
Registered User
 
Join Date: Apr 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Anyone have any ideas on this?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble returning most recent transaction with sql statment Dumb Dan ASP.NET 2.0 Professional 3 April 5th, 2011 10:25 PM
Hard SQL languge statment Questioin Mangore SQL Language 8 October 27th, 2008 03:01 AM
Using VB.Net to change the SQL Statment yicksang BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 March 31st, 2006 04:17 AM
SQL Statment btpoole VB Databases Basics 1 February 18th, 2004 01:03 PM
SQL statment arshad mahmood VB Databases Basics 1 July 1st, 2003 02:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.