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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql Server 7 - Most recent date

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I want to write query to retrieve the most recent date, such as:

SELECT Recent('2001-02-03','2001-12-12',...)

Is there a way to deal with this ?(I couldn't create a function with my Sql Server 7, is it normal ?)

Thanks

Vincent
 
select max t.t from
(select .datediff(d,dateCol,getDate()) t..) t John Fill
1c.bmp


ivfmd@mail.md
 
Hi Vincent,
John's query is going to give you correct result.
But the same result you can get just by giving this query.

SELECT MAX(myDateColumn) FROM myTable

 
The problem is that the different date are in different tables and in different fields ...

SELECT Recent(SELECT ... FROM ... WHERE ...,
SELECT ... FROM ... WHERE ...,
...)

Vincent
 
Hi Vincent,

Still you can use the same login in this way
------------------------------
SELECT max(myNewDateColumn) FROM (
SELECT myNewDateColumn=max(table1Date) FROM table1 WHERE ..
UNION
SELECT myNewDateColumn=max(table2Date) FROM table2 WHERE ..
UNION
SELECT myNewDateColumn=max(table3Date) FROM table3 WHERE ..
) A
------------------------------

Hope this will solve your problem!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top