急问一个SQL语句????

hexinyu2005 2006-08-18 01:37:18
表A
aid bid cid tvalue
1 2 3 0
9 1 2 0

表B
aid bid cid tvalue
1 2 3 6
91 1 2 8

把表B的数据插入到表A中去,其中aid的9是一个特殊的数据,忽略9后面的
结果喜欢是

aid bid cid tvalue
1 2 3 6
9 1 2 8
...全文
119 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenqianlong 2006-08-18
  • 打赏
  • 举报
回复
更新A
update A set a.tvalue=b.tvalue
from A,B
where left(a.aid,1)=left(b.aid,1) and a.bid=b.bid and a.cid=b.cid
插入:
insert A (aid,bid,cid,tvalue)
select left(aid,1),bid,cid,tvalue from B
子陌红尘 2006-08-18
  • 打赏
  • 举报
回复
update 表A
set
tvalue=表B.tvalue
from
表B
where
表A.aid<=9 and 表A.aid=表B.aid and 表A.bid=表B.bid and 表A.cid=表B.cid

34,593

社区成员

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

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