我下面執行查詢,這讓我Microsoft SQL Server錯誤102
SELECT
t1.s_reference "Section",
t2.m_reference "CourseRef",
t2.m_name "CourseName",
t3.mi_q02m02 "Aim",
t2.m_level "Level",
t2.m_start "Start",
t2.m_end "End",
t2.m_projstudents "Target",
COUNT(DISTINCT t4.e_id) "Enrolled"
FROM
isr t3,
person t5,
department t6,
section t1,
enrolment t4,
course t2
WHERE
t3.mi_id(+)=t2.m_id
AND t4.e_module=t2.m_id
AND t4.e_student=t5.p_id
AND(t2.m_status LIKE '%%'||SUBSTR((TO_CHAR(sysdate,'YYYY')+DECODE(least(to_number(TO_CHAR(sysdate,'mm')),8),8,0,-1)),-2,2) ||'%%')
AND t2.m_reference LIKE 'LL%%'
AND t4.e_status IN('C','S')
AND to_date(t2.m_start,'DD-Mon-RRRR')<=to_date(sysdate,'DD-Mon-RRRR')
AND to_date(t2.m_end,'DD-Mon-RRRR')>=to_date(sysdate,'DD-Mon-RRRR')
AND t2.m_modulesection=t1.s_id
AND t2.m_moduledept=t6.d_id
AND NVL(t2.m_close,0)=0
AND t3.mi_q02m02 IS NOT NULL
AND((
CASE
WHEN((t1.s_reference='LL2a')
AND(t2.m_reference LIKE '%W%'))
THEN 1
ELSE 0
END)=0)
AND(t2.m_reference!='LL3036E15')
GROUP BY
t1.s_reference,
t2.m_reference,
t2.m_name,
t3.mi_q02m02,
t2.m_level,
t2.m_start,
t2.m_end,
t2.m_projstudents,
t1.s_reference,
t2.m_reference
ORDER BY
t1.s_reference,
t2.m_reference
在執行查詢時出錯。
Incorrect syntax near ')'. MS SQL Server Error 102
我在SQL Developer中運行相同的查詢,它運行良好。
我試圖刪除大部分的括號,但仍然沒有幫助。 任何想法爲什麼發生這種情況?
感謝 阿魯娜
哪一行是一個問題? (刪除能夠正常工作的代碼,並保留儘可能小的問題查詢。) – jarlh
(可能)與您的錯誤無關,但您應該切換到明確的「join」語法,這是自1992年以來的標準! – HoneyBadger
當然你會得到錯誤。您已編寫Oracle代碼,並且您正在收到SQL Server錯誤。您應該使用SQL Server約定編寫代碼。 –