求一更新语句

lvxianda 2011-03-25 05:59:55
tbCategory表
categoryID categoryName
1 a
2 b

tbItem表
itmeID itemName categoryID
1 aaa 1
2 bbb 1
3 ccc 2

我想将tbCategory表中categoryName = a的数据 在tbItem表中对应的itemName 的内容前面加一个 * 号
希望结果如下
tbItem表
itmeID itemName categoryID
1 *aaa 1
2 *bbb 1
3 *ccc 2

...全文
77 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Music杰 2011-03-25
  • 打赏
  • 举报
回复
categoryname = 'a'好像不能给死的吧!
htl258_Tony 2011-03-25
  • 打赏
  • 举报
回复
update b set b.itemName ='*'+b.itemName 
from tbCategory a,tbItem b
where a.categoryID =b.categoryID
快溜 2011-03-25
  • 打赏
  • 举报
回复
update tbItem set itemName='*'+itemName
AcHerat 元老 2011-03-25
  • 打赏
  • 举报
回复

update tbItem
set categoryName = '*' + categoryName
where categoryID in (select categoryID from tbCategory where categoryname = 'a')
AcHerat 元老 2011-03-25
  • 打赏
  • 举报
回复

select itemID,(case when categoryID in (select categoryID from tbCategory where categoryname = 'a')
then '*' + itemname else itemname end)itemname,categoryID
from tbItem

34,587

社区成员

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

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