查询:
UPDATE EMPLOYEE AS E
INNER JOIN EMPLOYEE_TEL AS T ON E.EMP_NUMBER = T.EMP_NUMBER
SET E.FIRST_NAME = @fname
,E.MID_NAME = @mname
,E.INITIALS =@initilas
,E.SURNAME = @sname
,E.GENDER = @gender
,E.CIVIL_STATUS = @CS
,E.DOB =@datetime
,E.NIC_NUMBER = @nic
,E.ADDRESS_LINE1 =@adline1
,E.ADDRESS_LINE2 = @adline2
,E.ADDRESS_LINE3 = @adline3
,E.EMAIL = @email
,E.DESG_NO =@designo
,E.BASIC_SALARY = @sal
,E.TITLE = @title
,T.TELEPHONE=@tel
WHERE E.EMP_NUMBER=@empnum
我在这个SQL Server中尝试过,但它出现了错误
'Msg 156,Level 15,State 1,Procedure SPUPDATEEMP,Line 21
关键字“AS”附近的语法不正确。
我找不到错误。这是错的吗?
答案 0 :(得分:2)
UPDATE EMPLLOYEE
SET FIRST_NAME = @fname
,MID_NAME = @mname
,INITIALS =@initilas
,SURNAME = @sname
,GENDER = @gender
,CIVIL_STATUS = @CS
,DOB =@datetime
,NIC_NUMBER = @nic
,ADDRESS_LINE1 =@adline1
,ADDRESS_LINE2 = @adline2
,ADDRESS_LINE3 = @adline3
,EMAIL = @email
,DESG_NO =@designo
,BASIC_SALARY = @sal
,TITLE = @title
WHERE EMP_NUMBER=@empnum
UPDATE EMPLOYEE_TEL
SET TELEPHONE=@tel
WHERE EMP_NUMBER=@empnum
答案 1 :(得分:0)
进行JOINS时,您不需要使用“as”来为表名设置别名。
但是,在进行更新时,您不能像想要的那样为名称添加别名。
UPDATE E
FROM Employee
答案 2 :(得分:0)
您要做的是一次更新两个表 - 您无法在SQL Server中执行此操作 - 您必须将其拆分为两个单独的更新:
UPDATE EMPLOYEE
SET
FIRST_NAME = @fname,
MID_NAME = @mname,
.....
TITLE = @title
WHERE
EMP_NUMBER = @empnum
UPDATE EMPLOYEE_TEL
SET
TELEPHONE = @tel
WHERE
EMP_NUMBER = @empnum