alter procedure dbo.d as begin declare @TotalPickedUp int =0 set @TotalPickedUp=(( SELECT count(*) FROM ( SELECT c.courierid , rn = ROW_NUMBER() OVER (PARTITION BY cs.courierid ORDER BY date DESC) FROM courierstatus_tracker cs inner join courier c on c.courierid=cs.courierid where cast(c.courierdate as date)='2014-07-24 00:00:00.000' and (cast(cs.Pickedup_ActualDate as date)<=cast('2014-07-28 00:00:00.000' as date) or cast(cs.date as date)<=cast('2014-07-28 00:00:00.000' as date) ) and c.Productorservices='Reverse Pickup' and cs.reasonid>=31) bt WHERE rn = 1)) select @TotalPickedUp as data end
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)