January 20, 2011 at 9:32 am
this is what i have and it works perfect but i need to add data from a 3rd table
Select
Orders.OrderDate,
Orders.OrderId,
Orders.OrderNotes,
Orders.Custom_field_vehicleinfo,
Orders.Salesrep_Customerid,
OrderDetails.ProductCode,
OrderDetails.Productname,
From Orders
join Orderdetails
on orders.orderid = orderdetails.orderid
Where Orders.Orderstatus in ('Pending', 'Processing', 'New')
Order By Orders.Orderdate ASC
The third table is called products and all i need is to select the customfield4 and have it print with the rest of these... so it should look like
Select
Orders.OrderDate,
Orders.OrderId,
Orders.OrderNotes,
Orders.Custom_field_vehicleinfo,
Orders.Salesrep_Customerid,
OrderDetails.ProductCode,
OrderDetails.Productname,
Products.CustomFeild4
From Orders
join Products
join Orderdetails
on orders.orderid = orderdetails.orderid
Where Orders.Orderstatus in ('Pending', 'Processing', 'New')
Order By Orders.Orderdate ASC
January 20, 2011 at 10:34 pm
This is actually quite simple, unfortunately I can't help you as you haven't provided the DDL (CREATE TABLE statements) for the tables involved, sample data for the tables to test with, and the expected results based on the sample data you provide.
Please remember we can't see what you you see unless you provide us with the information we need to be able to help you.
January 21, 2011 at 5:07 am
Just a wild stab in the dark, but I think you want something like this:
SELECT
Orders.OrderDate,
Orders.OrderId,
Orders.OrderNotes,
Orders.Custom_field_vehicleinfo,
Orders.Salesrep_CustomerId,
OrderDetails.ProductCode,
OrderDetails.ProductName,
Products.CustomField4
FROM
Orders
INNER JOIN
OrderDetails
ONOrders.OrderId = OrderDetails.OrderId
INNER JOIN
Products
ONOrderDetails.ProductId = Products.ProductId
WHERE
Orders.OrderStatus IN ('Pending', 'Processing', 'New')
ORDER BY Orders.OrderDate ASC
January 21, 2011 at 5:24 am
Is there something wrong with all the answers I gave you on the other thread you had on this problem? http://www.sqlservercentral.com/Forums/Topic1050944-391-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply