0
我有以下5個表:UNION ALL FROM SELECT語句不工作
TABLE OLD_A (CID, CNO, CNAME)
TABLE OLD_B (DID, DNO, DNAME)
TABLE OLD_MAP (CID, DID, TERRITORY)
TABLE NEW_A (NCID, NCNO, NCNAME)
TABLE NEW_MAP (NCNO, DNO, TERRITORY )
我想CNO
和CNAME
由新的和舊錶,所以我做了下面的查詢
[email protected] varchar(16), @DNO varchar(16)
SELECT RESULT.`enter code here`CNO as CNO, RESULT.CNAME as CNAME, RESULT.Is_New_Or_Old as Is_New_Or_Old
FROM
(
(SELECT C.CNO as CNO, C.CNAME as CNAME, 'OLD' AS Is_New_Or_Old [OLD_A] AS C LEFT JOIN [OLD_MAP] AS DCL ON C.ID = DCL.CID JOIN [OLD_B] AS D ON DCL.DID = D.ID WHERE C.TERRITORY = @TERRITORY AND D.DNO = @DNO)
UNION ALL
(SELECT NC.NCNO as CNO, NC.CNAME as CNAME, 'NEW' AS Is_New_Or_Old FROM [NEW_A] AS NC LEFT JOIN [NEW_MAP] AS CDTL ON NC.NCNO = CDTL.NCNO WHERE CDTL.DNO = @DNO AND CDTL.Territory_Id = @TERRITORY)
) RESULT
ORDER BY CNO
但給我錯誤
Incorrect syntax near ')'.
最後)
噢,那是如此愚蠢的錯誤我做了.... – Dhwani
你coludn't看到它是可以避免的,因爲你沒有格式化您的查詢。我建議你總是這樣做 – Alexander
非常感謝。下次會做。 – Dhwani