更新字段出错

wuzhibumian 2011-11-08 03:56:38
update employee set employee.educationid=k.educationid
from (select employeeid ,educationid c ,max(beginenddate_enddate) from Employeeeducation
where educationid is not null
group by employeeid,educationid ,[name])k
where k.employeeid=employee.employeeid
...全文
64 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2011-11-08
  • 打赏
  • 举报
回复
在更新的时候 子查询的得到的字段需要取别名。
中国风 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wuzhibumian 的回复:]

引用 5 楼 acherat 的回复:

注意子查询的别名问题。

你确实是解决问题了,为什么要加这个,我用2000的时候没有这个问题呀,用2008有这个问题
as col 是给哪个取别名
[/Quote]

update employee
set employee.educationid=k.educationid
from (select employeeid ,educationid,max(beginenddate_enddate) as c from Employeeeducation
where educationid is not null
group by employeeid,educationid ,[name])k
where k.employeeid=employee.employeeid

紅色的位置,別名你放錯了
wuzhibumian 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 acherat 的回复:]

注意子查询的别名问题。
[/Quote]
你确实是解决问题了,为什么要加这个,我用2000的时候没有这个问题呀,用2008有这个问题
as col 是给哪个取别名
中国风 2011-11-08
  • 打赏
  • 举报
回复
update employee 
set employee.educationid=k.educationid
from (select employeeid ,educationid,max(beginenddate_enddate) from Employeeeducation
where educationid is not null
group by employeeid,educationid ,[name])k
where k.employeeid=employee.employeeid



educationid c --這里多了一個c別名
Mr_Nice 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 acherat 的回复:]

from (select employeeid ,educationid c ,max(beginenddate_enddate) as col from Employeeeducation
[/Quote]

+ 注意别名
快溜 2011-11-08
  • 打赏
  • 举报
回复
update employee set employee.educationid=k.educationid
from employee,(select employeeid ,educationid c ,max(beginenddate_enddate) from Employeeeducation
where educationid is not null
group by employeeid,educationid ,[name])k
where k.employeeid=employee.employeeid
AcHerat 2011-11-08
  • 打赏
  • 举报
回复
注意子查询的别名问题。
AcHerat 2011-11-08
  • 打赏
  • 举报
回复
from (select employeeid ,educationid c ,max(beginenddate_enddate) as col from Employeeeducation
wuzhibumian 2011-11-08
  • 打赏
  • 举报
回复
是什么问题呀?
wuzhibumian 2011-11-08
  • 打赏
  • 举报
回复
消息 8155,级别 16,状态 2,第 1 行
没有为 'k' 的列 3 指定任何列。
wuzhibumian 2011-11-08
  • 打赏
  • 举报
回复
这个报消息 8155,级别 16,状态 2,第 1 行
没有为 'k' 的列 3 指定任何列。

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧