Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Help!

Status
Not open for further replies.

Wallie12

MIS
Mar 5, 2004
92
US
I have multiple line of input data as such:
Number, Starttime, Targettime, Endtime
SVR227408,3/24/2010 4:34:24 PM,4/7/2010 4:34:24 PM,4/6/2010 10:35:06 PM
SVR227408,12/7/2009 2:18:27 AM,12/8/2009 9:00:00 PM,12/7/2009 8:43:14 PM
SVR227408,12/7/2009 2:18:27 AM,12/8/2009 9:00:00 PM,12/7/2009 8:43:14 PM
SVR227408,12/7/2009 2:18:27 AM,12/7/2009 8:30:00 PM,12/7/2009 2:19:17 AM ......etc.
SVR224509,
SVR609210,

What I need is the following
SELECT [Number] ---> where Number is Distinct
,[Dateopened]
,[Closed]
,[Starttime]
,[Targettime] ----> and Targettime is MAX
,[Endtime]
FROM [TC].[dbo].[APPLY_DATES_S]

Thanks in advance
Brianmahler@msn.com
 
Code:
SELECT t.Number 
     , t.Dateopened 
     , t.Closed 
     , t.Starttime 
     , t.Targettime
     , t.Endtime  
  FROM ( SELECT Number
              , MAX(Targettime) AS maxtime
           FROM TC.dbo.APPLY_DATES_S
         GROUP
             BY Number ) AS m
INNER
  JOIN TC.dbo.APPLY_DATES_S AS t
    ON t.Number = m.Number
   AND t.Targettime = m.maxtime

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Tried the code. The result I was looking for was:
Number Targettime
SVR349075 4/13/2010 3:30:00 AM<=== this one
SVR349075 4/13/2010 9:00:00 AM
SVR349075 4/9/2010 4:00:00 AM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top