【发布时间】:2017-07-27 07:04:27
【问题描述】:
我想返回空值以防万一。这是我的查询
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 = case when (select count(BR_ProductPrice.ID) from BR_ProductPrice where BR_ProductPrice.CountryID = @CountryID) > 0 Then @CountryID else Null 结束
我希望 CountryId 比较 else 部分中 case 语句的 null 部分,类似这样
然后@CountryID 否则 Country.CountryId 为空
当我通过 CountryID = 1101 时,查询工作正常。
【问题讨论】:
-
select count(BR_ProductPrice.ID) from BR_ProductPrice where BR_ProductPrice.CountryID = @CountryID返回 1? -
@Pream 它返回我 0
-
检查我下面的答案是否有效
标签: sql-server sql-server-2008