积极答复者
两条语句一样,但执行结果却不一样?

问题
-
update employee set emp_id=t.rowId from ( select * from employee where Emp_UserName=employee.Emp_UserName ) as t
the statement is executed correctly.
but,the follow statement is wrong when it being executed,why?
update employee set emp_id=t.rowId from ( select * from employee as t1 -- alias is t1 where t1.Emp_UserName=employee.Emp_UserName ) as t
消息 4104,级别 16,状态 1,第 13 行
无法绑定由多个部分组成的标识符 "employee.Emp_UserName"。
yanglei
- 已编辑 Lane3000 2012年5月30日 9:20
答案
-
( select * from
employee as t1 -- alias is t1
where t1.Emp_UserName=employee.Emp_UserName
) as t这个的意思,是为 employee 的每条记录,去执行一次子查询,这不是 JOIN 语句支持的,CROSS APPLY 或者 OUTER APPLY 才支持
当然,从你的目的(另一个帖子)来看,你是不应该使用 APPLY 的,是你把条件写错了位置
全部回复
-
( select * from
employee as t1 -- alias is t1
where t1.Emp_UserName=employee.Emp_UserName
) as t这个的意思,是为 employee 的每条记录,去执行一次子查询,这不是 JOIN 语句支持的,CROSS APPLY 或者 OUTER APPLY 才支持
当然,从你的目的(另一个帖子)来看,你是不应该使用 APPLY 的,是你把条件写错了位置