设置别名变量

时间:2013-07-10 14:49:13

标签: sql sql-server-2005 stored-procedures alias

我有来自SQL Server Management Studio 2005的以下T-SQL代码:

UPDATE O
SET DATAREVISIONTYPE = 'Modify', O.OriginalUserID = OriginalUserID, O.EmployeeBirthdate = EmployeeBirthdate, O.User_ID = User_ID
FROM LRN_Upload_Prep as O
WHERE DATAREVISIONTYPE = 'Add' AND
(SELECT COUNT([OriginalUserId]) FROM Lrn_Upload_Prep WHERE DataRevisionType = 'Transfer' AND FirstName = O.FirstName 
AND LastName = O.LastName AND EmployeeEmailAddress = O.EmployeeEmailAddress AND LEFT(EmployeeBirthdate, 4) = O.EmployeeBirthdate)> 0

我无法弄清楚如何使用别名修改SET中的数据(O.OriginalUserID = OriginalUserID,O.EmployeeBirthdate = EmployeeBirthdate,O.User_ID = User_ID),因为我的理解是别名尚未声明。我考虑将在CTE中声明别名的部分包裹起来,想想也许会起作用,但无济于事。对研究内容的任何修正或建议都很棒,谢谢!

0 个答案:

没有答案