如果INNER JOIN可以使用单个表但条件不同吗? 我想知道是否可以将以下查询合并为一个:
UPDATE st
SET st.GLAccount = gt.GLAccount
FROM StockTransactions st
INNER JOIN GLTransactions gt ON gt.TransactionID = st.PurchaseTransactionID
AND gt.Quantity IS NOT NULL AND st.Item = gt.Item
Go
UPDATE st
SET st.GLAccount = gt.GLAccount
FROM StockTransactions st
INNER JOIN GLTransactions gt ON gt.TransactionID = st.ID AND st.Item = gt.Item
AND (st.Type = 160 OR st.Type = 165)
GO
UPDATE st
SET st.GLAccount = gt.GLAccount
FROM StockTransactions st
INNER JOIN GLTransactions gt ON gt.TransactionID = st.ID AND st.Item = gt.Item
AND gt.LineType = 1
GO
答案 0 :(得分:2)
怎么样:
UPDATE st
SET st.GLAccount = gt.GLAccount
FROM StockTransactions st
INNER JOIN GLTransactions gt ON ( gt.TransactionID = st.PurchaseTransactionID
AND gt.Quantity IS NOT NULL
AND st.Item = gt.Item
)
OR ( gt.TransactionID = st.ID
AND st.Item = gt.Item
AND ( ( st.Type = 160
OR st.Type = 165
)
OR gt.LineType = 1
)
)