I have Product Table & priceDeatil table.
Prouct Table
ProductCode BusinessUnit
10001 ORB
10002 ORB
StockRecord Table
ProductCode Name StcokQuantity
10001 SUnSilk 1000
10002 Pen 500
priceDeatil
ProductCode BusinessUnit price DateFrom DateTo
10001 ORB 12.00 12-08-2011 31-09-2015
10001 ORB 21.00 01.08-2011 15-09-2011
10002 ORB 54.00 21.08-2011 15-09-2011
I want to get the product table's record,StockRecords's table & price with that product latest price
Here productCode 10001 contain 2 records when I run query it return 2 reords.I want to get only one records.
SELECT WMProduct.BusinessUnit, WMProduct.ProductCode, StockRecord.Name, WMPriceDetail.Price
FROM WMProduct INNER JOIN StockRecord
ON WMProduct.ProductCode = StockRecord.ProductCode
INNER JOIN WMPriceDetail
WMPriceDetail ON WMProduct.BusinessUnit = WMPriceDetail.BusinessUnit AND WMPriceDetail.ProductCode = WMProduct.ProductCode
WHERE (WMPriceDetail.DateFrom < GETDATE()) AND (WMPriceDetail.DateTo > GETDATE() OR
WMPriceDetail.DateTo = NULL)
This query returns
BusinessUnit ProductCode Name Price
ORB 10001 SunSilk 12.00
ORB 10001 SunSilk 21.00
But I need only one records.... BusinessUnit ProductCode Name Price ORB 10001 SunSilk 21.00 ORB 10002 Pen 54.00
From that query i can't put TOP 1 because there are more table combine.. join
If the price is not define in the price detail table, that records should not show into the list.
Please help me....
Thanks in advance