Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends.
I need to get latest updated data for every courierid from this procedure . When i am running this code independenatly , it is working fine .But in procedure it is always returning zero.Please help me .

SQL
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
Posted
Updated 6-Aug-14 2:32am
v2
Comments
Corporal Agarn 29-Jul-14 13:24pm    
Are you sure the stored procedure has permission to the database? Also double check the parenthesis as I think there may be a problem there.
Thava Rajan 6-Aug-14 8:45am    
there are things you need to clarified
since you are return only one valriable
how did you get the values for multiple counterid?
do you need only one value for the one counterid if yes where is the @counterid vairable
what are the date values why did they are hardcoded?
why are you return the count?
Suvendu Shekhar Giri 3-Jan-15 12:55pm    
Question title is misleading. You are saying you have problem with your stored procedure but title is about partition by clause.

Just for a hit-n-try, replace SET with SELECT.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900