Click here to Skip to main content
15,887,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have table customer(CustomerID,CustomerName),,, Item_master(Item_code,Item_Name)
sales_Order(orderno,customerId) and orderdetails(Orderno,item_code,qty)


i want sql query or view in which all orderdetails order to display.
like

orderno|CustomerName|Item_Name|qty

please guide...

What I have tried:

select SalesOrder.OrderNo,ItemMasterFile.Descriptionitem,
OrderDetail.orderqty,Customer.CustomerName from OrderDetail 
inner join ItemMasterFile on ItemMasterFile.CodeItem=OrderDetail.CodeItem
inner join Customer on Customer.CustomerID=SalesOrder.CustomerID
Posted
Updated 12-Apr-19 1:44am
Comments
CHill60 12-Apr-19 7:07am    
What is wrong with the code you have tried?

You have missed out the join to the SalesOrder table. E.g.
SQL
select S.OrderNo,I.Item_Name,OD.qty,C.CustomerName 
from sales_Order S
inner join orderdetails OD ON OD.Orderno = S.orderno
inner join Item_master I on I.Item_code=OD.Item_code
inner join Customer C on C.CustomerID = S.customerId
Note the table and column names in my solution are those that you mentioned in your description and not those that you have used in your code. I was not inclined to go back and change them.
 
Share this answer
 
Comments
Maciej Los 12-Apr-19 8:12am    
5ed!
CHill60 12-Apr-19 9:02am    
Thanks Maciej
It makes it a lot easier to troubleshoot if you apply a little formatting to your query, and using a tool such as as Sql Studio should have red lined the query due to any errors. Especially if you tried running it
SQL
select SalesOrder.OrderNo
,      ItemMasterFile.Descriptionitem
,      OrderDetail.orderqty
,      Customer.CustomerName
from OrderDetail 
inner join ItemMasterFile on ItemMasterFile.CodeItem   =OrderDetail.CodeItem
inner join Customer       on Customer.CustomerID       =SalesOrder.CustomerID
The first thing you have in your SELECT list is SalesOrder.OrderNo, however; SalesOrder is neither the FROM source nor is it JOINed.

Another tip I recommend is to use aliases for the table names, it also helps in readability
SQL
SELECT  s.OrderNo
  ,    	i.Descriptionitem
  ,     d.Qty
  ,     c.CustomerName
FROM        Sales_Order  s				
INNER JOIN  OrderDetail  d ON s.OrderNo    = d.OrderNo
INNER JOIN  Item_master  i ON d.Item_code  = i.Item_code
INNER JOIN  customer     c ON c.CustomerID = s.CustomerID
 
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