我使用的是复杂的查询。我需要总是返回我的行,即使它没有发现任何东西。
SELECT
a.InventoryItemID,
a.Name,
a.RetailPrice,
b.MainGroupItemCode,
b.MainGroupItemID,
c.VatValue,
a.Code,
a.Weight,
b.MainGroupItemName,
a.RetailPrice2,
a.FreePrice,
case when isnull(e.IsActive,0)=1 and isnull(d.price,0)!=0 then d.Price else RetailPrice End as CustomPrice
from InventoryMaster a
join InventoryMainGroupItems b on a.MainGroupItemID=b.MainGroupItemID
join VatCodes c on b.VatCodeID=c.VatCodeID
join InventoryPrices d on d.InventoryItemID=a.InventoryItemID
join InventoryCatalog e on e.CatalogID=d.CatalogID
where a.InventoryItemID=2 and ISNULL(e.catalogID,1)=3
问题是在最后一行ISNULL(e.catalogID,1)= 3。在我的表不与3号。所以,它不返回我什么存在采用catalogId,但采用catalogId与1号。我已经设置,如果是空回到我1,遗憾的是我没有得到任何一行从我的背部查询。我怎样才能解决这个问题 ?
我的问题已经解决了,我只是想增加一个连接表与一个wheere条件isnide
SELECT *
from
(
SELECT t1.ID,
t1.Name,
COALESCE(t2.price,t1.Price) AS price ,
Row_number() OVER(partition BY t1.ID ORDER BY t1.ID) rn
FROM InventoryMaster t1
LEFT JOIN inventoryprices t2
ON t1.ID=t2.ID
LEFT join InventoryCatalog t3
ON t3.ID=t2.ID and t3.ID=2
where t1.ID=2
) t
WHERE t.rn=1
它返回我总是从第一个表清查retailprice
加入3周附近的cols选择的开始
d.InventoryItemID,
d.CatalogID,
e.CatalogID
然后从那里取出并ISNULL,并运行看看你。
这可能是因为
join InventoryCatalog e
needs
ON d.CatalogID=ISNULL(e.catalogID,1)