select * from ( select *
FROM (select customer_mst.CUST_ID,customer_mst.firstname,
boxdetail_mst.boxnumber,customer_mst.address,customer_mst.city,customer_mst.groups,
customer_mst.mobile,paymentlist_mst.amount as dueamount,case when datediff(dd,getdate(),due_date) = 0 then 1 else datediff(dd,getdate(),due_date) end days_left,
ROW_NUMBER() OVER(ORDER BY firstname desc) as RowNum
from customer_mst
inner join paymentlist_mst
on customer_mst.CUST_ID= paymentlist_mst.CUST_ID
left join boxdetail_mst
on customer_mst.CUST_ID= boxdetail_mst.CUST_ID
where is_active ='Y' and convert(date,due_date,103) >= convert(date,getdate(),103)) a
WHERE RowNum BETWEEN 1 AND (1 + 25) - 1 ) b where cust_id = 2 order by firstname descThis code show how to joins and count left date in SQL 2008.
