我尽力解释这个问题,我有一个子查询在一个表中查找一些文档信息,然后我需要使用INSERT INTO来获取返回的文档ID并单独查询它们数据表。
这就是我现在正在使用的
use DATABASE
Select * into #Audit
From [dbo].[workflow] A
Where object_id IN
(
Select DISTINCT ChangeHistory.document_id, ChangeHistory.account_number,
min(timestamp)
from [dbo].[xip_workflow] A
INNER JOIN (select B.*
from [dbo].[changehistory] B
where B.doc_status like ('New')
and user_login_name like ('System')
and button_push like (' ')
and B.account_number in ('11111111')
and B.work_queue_system_name in ('r_queue')
and B.document_type in ('A1','A2','A3')
and timestamp > '4/11/2017') ChangeHistory
ON ChangeHistory.[document_id] = A.[object_id]
group by document_id, ChangeHistory.account_number)