我遇到了一個子查詢問題,希望有人可以幫助我。SQL子查詢超過1個值
如果我運行以下命令:
select t4.code from OITM T0
INNER JOIN DLN1 T1 ON T1.[ItemCode] = T0.[ItemCode]
INNER JOIN ODLN T2 ON T2.[DocEntry] = T1.[DocEntry]
INNER JOIN ITM10 T3 ON T3.[ItemCode] = T0.[ItemCode]
LEFT JOIN ODCI T4 ON T4.[AbsEntry] = T3.[ISCommCode]
WHERE T2.DocEntry = '7060'
結果是:
雖然在某些情況下可能存在的值相匹配的所需的多行和其他人在做不同時。
我寫它有一個子查詢覈對這些結果,並顯示一條消息,如果在任一行和[code]列不包含一些特定的查詢:
IF(
(SELECT
T4.Code
FROM OITM T0
INNER JOIN DLN1 T1 ON T1.[ItemCode] = T0.[ItemCode]
INNER JOIN ODLN T2 ON T2.[DocEntry] = T1.[DocEntry]
INNER JOIN ITM10 T3 ON T3.[ItemCode] = T0.[ItemCode]
LEFT JOIN ODCI T4 ON T4.[AbsEntry] = T3.[ISCommCode]
WHERE T2.DocEntry = '7060') NOT IN ('22030010','22030001','22030009')
)
BEGIN
SELECT 'MESSAGE'
END
顯然,這將無法編譯如果它有返回超過1行:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
HAVING和他們編譯不顯示這顯然是錯誤的消息計數不工作。
這是可能的還是我吠叫錯了樹?
非常感謝。
如何只增加一個'where'子句來查詢? –