John Cassell
Well-known member
- Joined
- Mar 20, 2007
- Messages
- 65
- Programming Experience
- Beginner
Hi There,
Can someone help me work out the correct way to achieve this pls..
I have 2 tables with data as in the image below. I have a query which says 'Display item & price'. It has two parameters, Item and CustCode.
If I select '001' as the item and 'A000' as the CustCode then it will display "001, £200.00" which is correct because I want either CustPrice if there is one or failing that the List_Price. However if I select '001' as the customer and 'Z001' as the custCode then it returns no records because it can't find Z001 in the tbl_CustPrices table (This is entirely possible for a customer to not appear in that tbl because it may never have had a special price)
My code is below, hope someone can help. Thanks
Can someone help me work out the correct way to achieve this pls..
I have 2 tables with data as in the image below. I have a query which says 'Display item & price'. It has two parameters, Item and CustCode.
If I select '001' as the item and 'A000' as the CustCode then it will display "001, £200.00" which is correct because I want either CustPrice if there is one or failing that the List_Price. However if I select '001' as the customer and 'Z001' as the custCode then it returns no records because it can't find Z001 in the tbl_CustPrices table (This is entirely possible for a customer to not appear in that tbl because it may never have had a special price)
My code is below, hope someone can help. Thanks
VB.NET:
SELECT tbl_Items.item, COALESCE (tbl_CustPrices.CustPrice, tbl_Items.List_Price) AS Price
FROM tbl_Items CROSS JOIN
tbl_CustPrices
WHERE (tbl_Items.item = @Param1) AND (tbl_CustPrices.CustCode = @Param2) AND (tbl_CustPrices.item = @Param1)