次のSQLステートメントが機能していません。
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products])
次のSQLステートメントが機能していません。
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products])
おそらくを返しますNULL
。試す
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products]
WHERE foreignStockId IS NOT NULL )
私は通常、このタイプのクエリにNOTEXISTSを使用します
SELECT stock.idstock,
stock.descr
FROM [Inventory].[dbo].[Stock] stock
WHERE NOT EXISTS (SELECT *
FROM [Subset].[dbo].[Products] p
WHERE p.foreignstockid = stock.idstock)
おそらく
SELECT foreignStockId FROM
[Subset].[dbo].[Products]
クエリは少なくとも1つのNULL値を返します
EXISTSをお試しください
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE NOT EXISTS
(SELECT * FROM [Subset].[dbo].[Products]
where stock.IdStock =foreignStockId )