Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select isNull(Purchase.ProductCode,0)as'Product Code',
isNull(ps.Quantity,0) as 'Opening Stock',
isNull(Purchase.Quantity,0) as 'Purchase Quantity',  
isNull(Saleitem.Quantity,0) 'Sale Quantity'   
,isNull(ps.Quantity + Purchase.Quantity - Saleitem.Quantity,0) as 'Closing Stock',
convert(date,Purchase.date,101)as'Date'
from 
(select ProductCode,Quantity,CONVERT(date,DateTime,101)date  from stocktable
where Status='Purchase Entry' 
and  ProductCode = 4 
group by  ProductCode,Quantity,CONVERT(date,DateTime,101))Purchase 
Full join
(
select ProductCode,convert(date,DateTime,101)as date,SUM(quantity)as Quantity
from Stocktable 
where Status='Sale Entry'
group by  ProductCode ,convert(date,DateTime,101) 
)Saleitem
on Saleitem.ProductCode='4'
full join
(
select p.Quantity,p.productcode,p.vendorcode from purechaseStockreport p
group by p.Quantity ,p.productcode,p.vendorcode
)ps
on ps.productcode = '4'
or ps.productcode = '4'
DISTIselect isNull(Purchase.ProductCode,0)as'Product Code',
isNull(ps.Quantity,0) as 'Opening Stock',
isNull(Purchase.Quantity,0) as 'Purchase Quantity',  
isNull(Saleitem.Quantity,0) 'Sale Quantity'   
,isNull(ps.Quantity + Purchase.Quantity - Saleitem.Quantity,0) as 'Closing Stock',
convert(date,Purchase.date,101)as'Date'
from 
(select ProductCode,Quantity,CONVERT(date,DateTime,101)date  from stocktable
where Status='Purchase Entry' 
and  ProductCode = 4 
group by  ProductCode,Quantity,CONVERT(date,DateTime,101))Purchase 
Full join
(
select ProductCode,convert(date,DateTime,101)as date,SUM(quantity)as Quantity
from Stocktable 
where Status='Sale Entry'
group by  ProductCode ,convert(date,DateTime,101) 
)Saleitem
on Saleitem.ProductCode='4'
full join
(
select p.Quantity,p.productcode,p.vendorcode from purechaseStockreport p
group by p.Quantity ,p.productcode,p.vendorcode
)ps
on ps.productcode = '4'
or ps.productcode = '4'NIC
Posted
Updated 13-Nov-15 8:21am
v2
Comments
Patrice T 13-Nov-15 13:44pm    
No repost please
Tomas Takac 14-Nov-15 8:20am    
No chance that somebody will take the time to analyze that query. I suggest you analyze the problem yourself and post only the relevant part in some simplified form instead of just dumping your code and asking people to fix it.

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