我已经运行下面的代码,但NULL不显示在最终的查询结果。 我可以看到NULL被插入临时表中。当我在查询中调用变量时,NULL值不显示。表变量和NULLS
USE [AdventureWorks2014];
GO
SET NOCOUNT ON;
SET STATISTICS IO ON;
DECLARE @values TABLE
(
Value VARCHAR(MAX) NULL
)
INSERT INTO @values
VALUES (NULL), ('Black'), ('Blue'), ('Grey'), ('Multi'), ('Red'), ('Silver'), ('Silver'), ('Black'), ('White'), ('Yellow') --SELECT Value FROM @values;
SELECT Production.Product.Name, Production.Product.ProductNumber, Production.Product.Color, Production.Product.ListPrice, Production.Product.SIZE, Production.Product.[Weight], Production.Product.ProductLine, Production.Product.Class, Production.Product.STYLE, Production.ProductPhoto.ThumbNailPhoto, Production.ProductPhoto.LargePhoto FROM Production.Product INNER JOIN Production.ProductProductPhoto ON Production.Product.ProductID = Production.ProductProductPhoto.ProductID INNER JOIN Production.ProductPhoto ON Production.ProductProductPhoto.ProductPhotoID = Production.ProductPhoto.ProductPhotoID
--BEGIN CALLOUT A
WHERE --Production.Product.Color IS NOT NULL
(Production.Product.Color IN (SELECT Value FROM @values));
--END CALLOUT A
GO
小问题:
除了插入
NULL
为@values
的,试试这个。如果null未被插入到表变量中怎么办? –@ t-clausen.dk然后不要添加'OR'部分? –
因此当表变量的内容发生变化时更改sql?有趣的 –