我有以下查询,我从另一个子查询中选择where 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是整数字段。 我得到的错误是“关键字'附近的语法不正确'。”
答案 0 :(得分:2)
您需要一个表别名:
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'
) d
-------^
where @DocTaxID is not null ;
不知何故,我认为有一种更为简单的方式来表达这种逻辑,但是现在还不清楚它到底在做什么。