Sum of two different condition in one column

You can try the below –

SELECT ProductId, SUM(Quantity) AS Quantity 
FROM ProductStockIn 
WHERE  OrgName = @OrgName AND Statecode in( 'ADD','ORDER')
AND CreatedOn BETWEEN DATEADD(MS,3,@LastGenerationDate)
AND @GenerationDate 
GROUP BY ProductId
having count(distinct Statecode)=2

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top