Click here to Skip to main content
15,889,840 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
this is sql query :
SQL
select s.part_name as Part_Name,s.part_no as Part_No,s.uom as UOM,
sum(distinct er.quantity) as Excess,sum(i.Invoice_Quantity) as import,
s.available_quantity as Balance from dr_Stock s 
left join dr_ExcessReceipt er on s.part_no=er.part_no 
left join dbo.dr_InwardEntry i on s.part_no=i.part_no
where month(er.Date)='7' and month(i._date)='7'
group by s.part_No,s.part_Name,s.uom,s.available_quantity


This query is runnig without error but it is not giving me a desired output
i have three table dr_Stock,dr_ExcessReceipt and dr_InwardEntry.
column part_no in dr_stock is primary key and part_no in dr_ExcessReceipt and
part_no in dr_InwardEntry is foreign key of part_no in dr_stock ,
if there are data in both foregn key column's table then it is giving proper data
but if there is no data in any of table dr_ExcessReceipt or in dr_InwardEntry then
it not retrieve any data, just retrieve column name
i want that if there are no data in any of the foreign key column's table then it should retrieve data where data is available in any of the table

thank You !!
Posted
Updated 19-Jun-12 18:57pm
v3
Comments
Ganesan Senthilvel 20-Jun-12 0:56am    
SQL format

Hi Friend,

Instead of using condition for the tables used with left join use with on clause.

ex.
SQL
left join dr_ExcessReceipt er on s.part_no=er.part_no and month(er.Date)='7' 
left join dbo.dr_InwardEntry i on s.part_no=i.part_no and month(i._date)='7'
 
Share this answer
 
thank you very much sir,
Now i got my desired output !!!
 
Share this answer
 
Comments
Maciej Los 20-Jun-12 8:35am    
This is not an answer. Please, remove it. If you have any question or comment, use "Have any Question or Comment" button.

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