我无法获得此SQL查询来更新我的数据库激活表。这是我的问题: -
UPDATE Activities
SET CJSID = CJSEmpNum.StaffNumber
FROM CJSEmpNum
Where Activites.Name = CJSEmpNum.Surname + " " + CJSEmpNum.Forename
我认为我的问题是where子句。在活动编号中,名称存储为Smith John,在CJSEmpNum中,它存储在两个单独的列Surname和Forename中。
答案 0 :(得分:1)
试试这个:
UPDATE A
SET CJSID = C.StaffNumber
FROM Activities A
INNER JOIN CJSEmpNum C ON A.Name = RTRIM(LTRIM(C.Surname)) +' '+ RTRIM(LTRIM(C.Forename))
答案 1 :(得分:0)
您是否尝试过将此作为内部联接?有点像...
UPDATE
一个
SET
A.CJSID = CJSEmpNum.StaffNumber
从
CJSEmpNum
内部联接
活动A ON A.Name = CJSEmpNum.Surname +''+ CJSEmpNum.Forename