Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]
@branch int

AS
BEGIN

SET NOCOUNT ON;

select PS.sno, PD.productname,sum(PS.quantity) as quantity,PS.description from
K_RT_PurchaseDet PS
inner join K_RT_ProductDetails PD on PD.sno=PS.product where purchasedby=@branch
and PS.company=@company and modelno=@modelno
group by PS.quantity,PS.sno, PD.productname,PS.description
END


i want to sum quantity when there are many rows with same company and modelno
Posted
Comments
thatraja 27-Jan-14 2:46am    
You got any error for this query? what's that?
N.RamaRaju 27-Jan-14 2:49am    
no error but i think group by mistake
thatraja 27-Jan-14 2:50am    
What's the output when you execute this
N.RamaRaju 27-Jan-14 2:53am    
product quantity model
mobile 3 1

mobile 3 1
N.RamaRaju 27-Jan-14 2:54am    
i want like this

product quantity model
mobile 6 1

1 solution

Query should be like this. You don't need to put quantity in GROUP BY clause. And columns order should be same as SELECT clause.
SQL
ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]
@branch int

AS
BEGIN

SET NOCOUNT ON;

select PS.sno, PD.productname,PS.description,SUM(PS.quantity) as quantity from
K_RT_PurchaseDet PS
inner join K_RT_ProductDetails PD on PD.sno=PS.product where purchasedby=@branch
and PS.company=@company and modelno=@modelno
group by PS.sno, PD.productname,PS.description

END
 
Share this answer
 

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