Merge into Using
https://www.cnblogs.com/renxiaoren/p/5442352.html
DECLARE @Reader_temp TABLE (AID INT)
--2.具有阅读权限流程
MERGE INTO @Reader_temp
USING (SELECT DISTINCT MainAID FROM td_YWZC_Main_Reader WHERE UserName=@UserName ) R
ON AID=R.MainAID
when not matched then insert(AID) values(R.MainAID);
是插入到表变量后再查询