以下のSELECT
発言があります。
SELECT t.ID,
t.SiteID,
t.SpareID,
t.SpareLocationID,
t.Qty,
t.IsDefault
FROM TrainingDB.dbo.LocationsPerSpare t
WHERE t.SpareID IN
(SELECT s.SpareID
FROM TrainingDB.dbo.LocationsPerSpare s
WHERE s.SpareLocationID = t.SpareLocationID
AND s.SpareID = t.SpareID
GROUP BY s.SpareID
HAVING COUNT(CONVERT(VARCHAR(36), s.SpareID)) > 2)
ORDER BY t.SpareID
そのスクリプトを実行すると、 が返されますNULL
。ただし、以下のようにエイリアスを削除すると、t.
正常に動作します。
SELECT ID,
SiteID,
SpareID,
SpareLocationID,
Qty,
IsDefault
FROM TrainingDB.dbo.LocationsPerSpare
WHERE SpareID IN
(SELECT s.SpareID
FROM TrainingDB.dbo.LocationsPerSpare s
WHERE s.SpareLocationID = SpareLocationID
AND s.SpareID = SpareID
GROUP BY s.SpareID
HAVING COUNT(CONVERT(VARCHAR(36), s.SpareID)) > 2)
ORDER BY SpareID
これはかなり奇妙だと思います。何か案は?