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 5th, 2011, 03:42 PM
Registered User
 
Join Date: Apr 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default Tricky sql statement-showing most recent, unique, delivery destination

Apologize in advance if this is not posted in the correct format. I'm fairly new to asp and boy is it fun struggling..... I mean learning!

I am using asp.net 2.0 with a sql database using sql server 2005 and have a table with 4 columns.

as an example


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 --------------------23:00----------yes

I'm trying to make a sql statment to return into a gridview the most recent TubeDestination and TimeSent based on the TimeSent for each tubestation in the table but only show the TubeDestination and TimeSent if the TimeSent has occured more than on hour ago from the current time. As shown above there can be multiple deliveries to a tubedestination in the log but each will have its own time.


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've spent days on this and would love some help with this problem and if anyone had a nice wrox text suggestion for sql/databases. I like the wrox asp.net 2.0 proffesional book I have but it leaves me with a lot of questions about sql statements. Thanks in advance. Dan
 
Old April 5th, 2011, 10:17 PM
Registered User
 
Join Date: Apr 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I realized after posting here that it was better placed in the sql forum. Thank you for reading and if you were intrested the solution provided was:

SELECT TubeDestination, MAX(TimeSent)
FROM Table1
Where TimeSent < dateadd(hh,-1,getdate())
GROUP BY TubeDestination">





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
SQL Server 2005 Report Delivery kollirajeev BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 March 20th, 2007 06:46 AM
Recent articles not showing on articles page kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 December 16th, 2006 10:06 AM
Tricky asp/sql problem cedwards Dreamweaver (all versions) 8 June 13th, 2005 04:02 PM
Tricky SQL fastcorvette Access 2 October 10th, 2003 10:28 AM





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