0
我有以下查询,其中我从另一个子查询选择与WHERE条件从子查询选择选择其中条件抛出错误
if not exists
(select @DocTaxID from (select bundlechecklist.Bundle_TXN_ID, documentchecklist.Doc_Checklist_TXN_ID, documentchecklist.Doc_Type_Name from ecm.bundle_checklist_txn bundlechecklist
left outer join [ECM].[Document_Checklist_TXN] documentchecklist on documentchecklist.Bundle_TXN_ID = bundlechecklist.Bundle_TXN_ID
where bundlechecklist.originating_tran_id = "AMD"
and bundle_name = 'Line')
where @DocTaxID is not null)
begin
insert into [ECM].[Document_Checklist_TXN]
(bundle_txn_id, document_action_rule_id, action_rule_name, doc_type_name, cp_document_name, document_id, doc_status_code)
values
(1, 17, 'A', 'DEv', 'Dec', 12, 'Pend')
end
DocTaxID是整型字段。 而我得到的错误是“关键字附近的语法不正确”,其中'。“
你得到错误的原因是因为你没有别名你的子查询:'...和bundle_name'行')作为一个Where @DocTaxId ...'*然而*,你的查询doesn'没有任何意义。整个子查询被WHERE @DocTaxID IS NOT NULL段忽略。更不用说,这两个变量甚至不会在代码片段的其他地方使用。 *你能解释一下你正在试图用这个查询吗?* – Siyual
用你正在使用的数据库(可能是SQL Server)来标记你的问题。 –
是它的SQL服务器。对此感到抱歉 – user3331421