Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getting Max value

Author  Topic 

sasiharitha
Starting Member

2 Posts

Posted - 2006-08-23 : 18:54:33
Hi ,
I have a table like this
TABLE DOCUMENT
ID PUB_DATE UPLOAD_DATE VER_ID
1 8/23/2006 8/21/2006 4:02:12.771978 PM 20060821160210
2 8/23/2006 8/22/2006 9:37:15.278315 AM 20060822093713
3 8/22/2006 8/23/2006 3:45:49.487955 PM 20060823154547

Can you help me with SQL to retreive the row with id 2 based on maximum PUB_DATE and max UPLOAD_DATE

Thanks in advance
Sasi

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-08-23 : 21:02:08
Have you tried to write such a query and failed? Post what you have so far and we will correct you if need be.



Nathan Skerl
Go to Top of Page

sasiharitha
Starting Member

2 Posts

Posted - 2006-08-23 : 21:09:54
I am not able to write any meaningful thing yet
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-08-23 : 21:15:05
Ok, in the future, posting questions in this format will help you to get quick and accurate responses from forum members:

-- setup test data
declare @TableDocument table (ID int, PUB_DATE datetime, UPLOAD_DATE datetime, VER_ID varchar(50))
insert into @TableDocument
select 1, '8/23/2006', '8/21/2006', '4:02:12.771978 PM 20060821160210' union all
select 2, '8/23/2006', '8/22/2006', '9:37:15.278315 AM 20060822093713' union all
select 3, '8/22/2006', '8/23/2006', '3:45:49.487955 PM 20060823154547'

-- return all
select *
from @TableDocument

-- return desired resultset
select top 1
ID,
PUB_DATE,
UPLOAD_DATE,
VER_ID
from @TableDocument
order by PUB_DATE desc, UPLOAD_DATE desc


Nathan Skerl
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-24 : 02:26:39
quote:
Originally posted by sasiharitha

I am not able to write any meaningful thing yet


Read this link and post accordingly, then surely you will get the anwer from here very fast...

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Chirag
Go to Top of Page
   

- Advertisement -