
Need help with a tricky query
I have a table that has the following layout:
rowid, customerid, worknote, entrydate
Each customerid can have multiple worknotes. What I need
to do is get the 2 most current worknotes for each
customer and put them into 2 separate columns in a view
(e.g., customerid, worknote1, worknote2). Some customerid
may only have a single worknote.
I can build a correlated subquery to get the 2 most current
results per customerid but I can't figure out how to then
display them into multiple columns without cursoring, using
temp tables, etc.
This is the query that gets me the 2 most current records:
select * from CustomerWorknotes t1 where rowid in (select
top 2 t2.rowid from CustomerWorknotes
t2 where t2.customerid = t1.customerid order by entrydate
desc)
Any help would be appreciated.
Thanks.
-John