Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my sql query:-

SQL
select s.part_name as Part_Name,s.part_no as Part_No,s.uom as UOM,i.Stock_OnEntryDate as Opening_Balance ,sum(distinct i.invoice_quantity) as Import,sum(distinct   r.Return_Quantity)as Material_Return,sum(distinct p.Issue_Quantity) as Issue,sum(distinct er.Quantity)as Excess,sum(distinct sr.Quantity) as Short,s.available_quantity as Balance from dri_Stock s left join dri_InwardEntry i on 
s.part_no=i.part_no and month(i._date)='6' and year(i._date)='2012' left join dri_ReturnToCustomer r on s.part_no=r.part_no and month(r.date)='6' and year(r.date)='2012' left join dri_IssueToProd p on s.part_no=p.part_no and month(p.date)='6' and year(p.date)='2012' left join dri_ExcessReceipt er on s.Part_No=er.Part_No and month(er.date)='6' and year(er.date)='2012' left join dri_ShortReceipt sr on s.part_no=sr.part_no and month(sr.date)='6' and year(sr.date)='2012' group by s.part_name,s.part_no,s.uom,s.available_quantity 


i am getting error :
"Column 'dri_InwardEntry.Stock_OnEntryDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."

i dont want the sum of i.stock_onentrdate
there are moer than one entry of particular part_no entry,
i want the last entry i.stock_onentrydate of particular part_no for i.stock_onentrydate

for more info :
dri_Stock is table in that part_no is a primary key and all other table's part_no column is a foreign key of dri_Stock column part_no(i.e. primary key)
Posted

If I understand you correctly , the correct query should be as follows...


SQL
select s.part_name as Part_Name,s.part_no as Part_No,s.uom as UOM,max(i.Stock_OnEntryDate) as Opening_Balance ,sum(distinct i.invoice_quantity) as Import,sum(distinct   r.Return_Quantity)as Material_Return,sum(distinct p.Issue_Quantity) as Issue,sum(distinct er.Quantity)as Excess,sum(distinct sr.Quantity) as Short,s.available_quantity as Balance from dri_Stock s left join dri_InwardEntry i on
s.part_no=i.part_no and month(i._date)='6' and year(i._date)='2012' left join dri_ReturnToCustomer r on s.part_no=r.part_no and month(r.date)='6' and year(r.date)='2012' left join dri_IssueToProd p on s.part_no=p.part_no and month(p.date)='6' and year(p.date)='2012' left join dri_ExcessReceipt er on s.Part_No=er.Part_No and month(er.date)='6' and year(er.date)='2012' left join dri_ShortReceipt sr on s.part_no=sr.part_no and month(sr.date)='6' and year(sr.date)='2012' group by s.part_name,s.part_no,s.uom,s.available_quantity



Regards
 
Share this answer
 
Comments
hit91 24-Jun-12 11:38am    
Thank you sir
But max will give me maximum of stock_onentrydate ,i dont want that.
I want last entry of stock_onentrydate in month of particular part_no
SalCon 24-Jun-12 12:19pm    
try to play with the month function. Extract the month and use it in the group by and the select list.
hit91 25-Jun-12 0:14am    
No,it is not working ...

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