The below code is a result of a query i have created, it all works fine apart from one thing. I have Material ID’s for material names:
1 = bath
2 = sink
3 = toilet
The below works but displays sink for every material
Select cu.FName + ' ' + cu.SName as 'Name',
cu.Address1 + ', ' + cu.Address2 + ', ' + cu.Address3 as 'Dispatch Address',
cu.PostCode,
co.DateOrdered,
co.Material1,
ma.MaterialName,
co.material2,
ma.MaterialName,
ma.Price as 'Item Price'
from Customers cu
left join CustomerOrder co on co.CustomerID = cu.CustomerID
left join ItemOrder it on it.OrderID = co.OrderID
left join Materials ma on ma.MaterialID = co.Material1
or co.material2 = ma.MaterialItemID or co.material3 = ma.MaterialItemID
it displays as follows (just the materials are listed to stop confusion)
Material1 | MaterialName | Material2 | Material2Name | Material3 | Material3Name
1 Sink 2 Sink 3 Sink
Can anybody help with this?
There are a few ways that you can do this including using
JOINon thematerialstable multiple times to get the result: