如何才能在查询的同时对表进行操作?

现在有一张user表,一张role表。

    可以查到user的id和其对应的role的id,而且role id是用逗号分隔的。

我问题就是怎么样才能在用函数分隔role id后,用其查询到对应的role name后,再把这个name关联到user表里对应的user上去。

    我用的是sqlserver

mysql中已测试:

insert into student (class,age) select Parent,SiteNum from cate

你可以试一下

我一般是习惯用查询出来后,在修改的。因为查询不会影响数据,等查询出来的数据对了。再去修改对应的数据。
select a.* ,b.* from user a,role b
where a.id=(substring(b.id ,charindex(',',b.id )+1,len(str)-charindex(',',b.id )))--(找到2个表的关键字连接在一起,如果有分割符号。就先)
--(substring(b.id ,charindex(',',b.id )+1,len(str)-charindex(',',b.id )))--这个是截取逗号后面的
--如果查询的数据对了。如下就可以直接复制来修改的了

update user set user.user=b.name
from user a,role b
where a.id=(substring(b.id ,charindex(',',b.id )+1,len(str)-charindex(',',b.id )))

如不清楚,可以加我QQ630849360