database - sql server 2008 r2 update max(recent) date in a table -
i have table
i want update max (recent) enddate orderid = 12.
i tried this
update order_status set endtime = @starttime @orderid in ( select orderid order_status group @orderid having max (@startdate)
but doesn't complied, please right?
edit sorry , asked wrong, want update end in recent(startetime)
i mean . want update endtime value in row has recent starttime
please try:
;with t as( select *, row_number() on (order starttime desc) rnum order_status orderid=12 ) update top(1) t set endtime=@starttime
for multiple orderid, try
;with t as( select *, row_number() on (partition orderid order starttime desc) rnum order_status ) update t set endtime=@starttime rnum=1
Comments
Post a Comment