tbCategory表
categoryID categoryName
1            a
2            btbItem表
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

解决方案 »

  1.   


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

  2.   


    update tbItem
    set categoryName = '*' + categoryName
    where categoryID in (select categoryID from tbCategory where categoryname = 'a')
      

  3.   

    update tbItem set itemName='*'+itemName
      

  4.   

    update b set b.itemName ='*'+b.itemName 
    from tbCategory a,tbItem b
    where a.categoryID =b.categoryID 
      

  5.   

     categoryname = 'a'好像不能给死的吧!