我下面的查詢導致錯誤:附近有語法錯誤「加入」
Incorrect syntax near the keyword 'join'.
Select top 1
a.mkey, emp_received, a.mkey,
c.type_desc DOC_TYPE, a.doc_no INWARD_NO,
c.type_desc dept_received, c.type_desc EMP_RECEIVED,
convert(varchar, a.doc_date, 103) date,
a.to_user, a.No_of_pages, Ref_No, c.type_desc,
e.emp_name NAME,
ISNULL(e.Email_Id_Official, '[email protected]') EMAILID
from
inward_doc_tracking_hdr a
left join
type_mst_a c on a.doc_type = c.master_mkey
and
left join
type_mst_a c on a.dept_received = c.master_mkey
left join
emp_mst e on a.emp_received = e.mkey
where
a.emp_received is not null
and a.mkey = (select mkey
from inward_doc_tracking_hdr aa
where doc_no='IW/16/97')
我不知道爲什麼它是導致該錯誤
按照戈登的回答,我爲emp_received添加了一個左連接,但它不起作用
Select top 1 a.mkey,
cd.type_desc as DOC_TYPE, a.doc_no as INWARD_NO,
cr.type_desc as DEPT_RECEIVED, qr.type_desc as EMP_RECEIVED,
convert(varchar(255), a.doc_date,103) as date,
a.to_user, a.No_of_pages, Ref_No,
e.emp_name as NAME,
coalesce(e.Email_Id_Official, '[email protected]') EMAILID
from inward_doc_tracking_hdr a left join
type_mst_a cd
on a.doc_type = cd.master_mkey left join
type_mst_a cr
on a.emp_received = qr.master_mkey left join
type_mst_a st
on a.dept_received = cr.master_mkey left join
emp_mst e
on a.emp_received = e.mkey
where a.emp_received is not null and
a.mkey = (select mkey
from inward_doc_tracking_hdr aa
where doc_no = 'IW/16/97'
);
'和left join':這不是SQL構造。 –
通過刪除'和'仍然出現錯誤 – BNN
這是因爲'left.emp_received = qr.master_mkey上的type_mst_a cr'。你指的是'qr',你可能是指'cr'。 (請參閱Gordon的代碼。) – HoneyBadger