Sir,
I need your help in below query.
I need to use order by and UNION ALL in query given below in order to get 1000 rows in a single execution.
select strCustomerID, strDate, strUser, strAction from
( select top 1 *
from tblFollowupdetail where strCustomerID='AB7356'
and strDate between convert(datetime,'01/12/2016',103)
and convert(datetime,'15/12/2016',103)
order by strDate desc ) last

Manas MohapatraPosted Dec 19, 2016, 4:45 AM
ali tuncerPosted Dec 19, 2016, 4:07 AM
I think first you need to group by customer Id and get maxdate, so it will be latest record for each customer..then you can join this table to tblFollowupdetail to get other columns..
from tblFollowupdetail
group by strCustomerID
Nitin SontakkePosted Dec 19, 2016, 4:03 AM
Bineesh ViswanathPosted Dec 19, 2016, 3:51 AM
Nitin SontakkePosted Dec 19, 2016, 3:29 AM
select strCustomerID, strDate, strUser, strAction
from tblFollowupdetail
and strDate between convert(datetime,'01/12/2016',103)
and convert(datetime,'15/12/2016',103)
order by strDate desc
Bineesh ViswanathPosted Dec 19, 2016, 2:21 AM
select strCustomerID, strDate, strUser, strAction
from (
select top 1 *
from tblFollowupdetail where strCustomerID='AB9058'
and strDate between convert(datetime,'01/12/2016',103)
and convert(datetime,'15/12/2016',103)
order by strDate desc) last
union all
select strCustomerID, strDate, strUser, strAction
from (
select top 1 *
from tblFollowupdetail where strCustomerID='AB8120'
and strDate between convert(datetime,'01/12/2016',103)
and convert(datetime,'15/12/2016',103)
order by strDate desc) last
Manas MohapatraPosted Dec 19, 2016, 1:07 AM
Nitin SontakkePosted Dec 19, 2016, 12:24 AM