sql截取逗号分隔的字符串实例

//sql逗号分隔的字符串参数截取操作
1
create proc proc_update_userRole 2 (@IDs nvarchar(2000),@RoleID int) 3 as 4 declare @lloca int 5 declare @rloca int 6 declare @ID int 7 set @lloca=1 8 set @rloca=charindex(',',@IDs,@lloca) 9 while(@rloca is not null and @rloca<>0) 10 begin 11 set @ID= substring(@IDs,@lloca,@rloca-@lloca) 12 set @lloca=@rloca+1 13 set @rloca=charindex(',',@IDs,@lloca) 14 update sys_UserRoles set R_RoleID=@RoleID where R_RoleID in (select RoleID from egb_OrgUser where AutoID=@ID) and R_UserID in(select UserID from egb_OrgUser where AutoID=@ID) 15 update egb_OrgUser set RoleID=@RoleID where AutoID=@ID 16 end 17 go

 

posted @ 2015-10-09 18:29  ybyi  阅读(4483)  评论(0编辑  收藏  举报