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


Nitin SontakkeRank #264 · 9.6K reputationPosted Dec 18, 2016, 7:24 PM EST
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 18, 2016, 8:07 PM EST
Bineesh ViswanathRank #1,681 · 907 reputationPosted Dec 18, 2016, 9:21 PM EST
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
Nitin SontakkeRank #264 · 9.6K reputationPosted Dec 18, 2016, 10:29 PM EST
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 ViswanathRank #1,681 · 907 reputationPosted Dec 18, 2016, 10:51 PM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Dec 18, 2016, 11:03 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Dec 18, 2016, 11:07 PM EST
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
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 18, 2016, 11:45 PM EST