Okay I have a customer table with a child table with multiple records.
I need to select data from the parent table and join it the last record from the child table based upon a datetime field.
Something like this but without the error.
select customerid, AH.* from customer
LEFT OUTER JOIN (select top 1 customerid, agentid, inserteddatetime
from activityhistory AH
where AH.customerid = customer.customerid
order by inserteddatetime desc )
on AH.customerid = customer.customerid
The Error is:
Server: Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'on'.
I know it can be done, I've seen it before but I just can't remember where.
Fred Lauckner
You know, it works on my computer. I don't know what your problem is.
.Net aint so bad.