我想在返回null值的情況下。這是我的查詢如何在SQL Server 2008中的case語句中返回Null
Declare @MasterProduct nvarchar(50) = N'Sharepoint Easy Nav',
@ProductSlug nvarchar(50) = 'sharepoint-easynav-free',
@CountryID bigint = 1111;
SELECT
Product.ProductName,
Product.MasterProductName,
Price.ProductPrice,
Price.ProductTax,
Price.ProductTotalPrice,
Product.TotalSiteCollectionText,
Product.TotalSiteCollection,
Product.Is_Support,
Price.Is_Support_Price,
Product.ProductSlug,
Country.CountrySymbol,
Country.CountryId
FROM
BR_Product as Product
Inner Join BR_ProductPrice as Price on Product.ID = Price.ProductID
left Join BR_Country as Country On Price.CountryID = Country.CountryId
where Product.MasterProductName = IsNull(@MasterProduct, Product.MasterProductName)
and Product.ProductSlug = IsNull(@ProductSlug, Product.ProductSlug)
and Country.CountryId = case
when (select count(BR_ProductPrice.ID)
from BR_ProductPrice
where BR_ProductPrice.CountryID = @CountryID) > 0
Then @CountryID
else Null
end
它返回我沒有行。
當我刪除
Country.CountryId =情況下,當(SELECT COUNT(BR_ProductPrice.ID)從BR_ProductPrice其中BR_ProductPrice.CountryID = @CountryID)> 0然後@CountryID別的空 端
我想CountryId中的其他部分是這樣的
比較case語句的空部分然後@CountryID其他Country.CountryId爲空
查詢是否工作正常,當我通過CountryID = 1101
'SELECT COUNT(BR_ProductPrice.ID) CountryID'返回1? – Pream
@Pream它返回我0 –
檢查我的答案是否在工作 – Pream