这个update 怎么写?

hsie168518 2008-09-04 05:18:48
表A有5个字段


code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 4 3
3101 5 3 3 3


现在如果sort =3 的话,就更新qty, 让qty=qty1,
如果sort =1的话,qty=qty2
最后结果为如下


code qty1 qty2 qty sort
3101 5 6 6 1
3101 8 9 9 2
3101 7 4 7 3
3101 5 3 5 3


一句update怎么搞。
...全文
72 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jasonren 2008-09-04
  • 打赏
  • 举报
回复

update tb set qty=case when sort=3 then qty1 when sort=1 then qty2 end
天-笑 2008-09-04
  • 打赏
  • 举报
回复
update [table]
set qty = case when sort =3 then qty1 when sort =1 then qty2 else qty end
netcup 2008-09-04
  • 打赏
  • 举报
回复
update a set qty=case when sort=3 then qty1 when sort=1 then qty2 end

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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