我有一條SELECT語句,它根據我發送給它的員工ID的XML字符串查找記錄。TSQL在從select中獲取數據後插入到表中
它檢查某些標準以及檢查數據是否存在於另一個表中。
一旦返回數據,我需要那麼數據添加到它不是在發現表。
,我只是不知道如何,因爲我認爲這個代碼塊每次運行這會工作然後進入下一個插入行。
我怎樣才能將A.[employee]
中的每一個插入到它返回的另一個表中?
SELECT A.[employee],
Sup.SupEmpID,
Sup.Email,
Sup.FirstName,
Sup.LastName,
sum(A.[awardValue]) AS totalAwarded
FROM taxTracker AS A
INNER JOIN
EmpTable AS E
ON A.employee = E.EmpID
INNER JOIN
EmpTable AS Sup
ON E.SupEmpID = Sup.EmpID
WHERE YEAR(A.[awardDate]) = YEAR(GETDATE())
AND employee IN (SELECT ParamValues.x1.value('empID[1]', 'VARCHAR(50)')
FROM @awardEmployees.nodes('/employees/employee') AS ParamValues(x1))
AND NOT EXISTS (SELECT employee
FROM taxTrackerTracked
WHERE [year] = YEAR(GETDATE())
AND employee IN (SELECT ParamValues.x1.value('empID[1]', 'VARCHAR(50)')
FROM @awardEmployees.nodes('/employees/employee') AS ParamValues(x1)))
GROUP BY employee, Sup.SupEmpID, Sup.Email, Sup.Firstname, Sup.LastName
HAVING SUM(A.[awardValue]) > '75.00'
FOR XML PATH ('data'), TYPE, ELEMENTS, ROOT ('root');
--An insert statement here
你需要回從上面的查詢返回結果集到客戶端,或剛插入值到一個表,而不返回任何結果集? –
插入語句應該插入到'taxTrackerTracked'還是其他表? –
更正到跟蹤表中。示例:獲取不在該表中的數據,現在將其添加到該表中,但我也有XML輸出中的數據與原始選擇一起使用 – SBB