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
 Transact-SQL (2000)
 Max date

Author  Topic 

sippon77
Starting Member

13 Posts

Posted - 2005-04-06 : 05:54:05
how do i get the max date (the latest one). currently i am doing the following:

select top 1 @incidentid = vin.iincidentid,
@prodesc = qd.vchdescription ,
@unitprice = cast(cast(qd.flunitprice as bigint) as varchar)
from vincident vin
join vquoteheader qh
on qh.isystemid = vin.iincidentid
and vin.iincidentcategory =3
join vquotedetail qd
on qd.iquoteid = qh.iquoteid
where vin.iownerid = @cid
order by vin.dtupdatedate desc

but i dont want to be using 'order by' and 'top'.

Thanks in advance!!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-04-06 : 06:09:40
use max(dateColumn)
and group by

Go with the flow & have fun! Else fight the flow
Go to Top of Page

kimberr
Starting Member

9 Posts

Posted - 2005-04-06 : 06:20:12
If you want to return the iincidentid relating to the iownerid record with the MAX date. Add this where clause to main query:

where [datefield] = (select max([datefield]) from vincident where vin.iownerid = @cid)
Go to Top of Page
   

- Advertisement -