SQL 分割字符串

 1 --插入选中了父节点的id
 2         while CHARINDEX(',',@PMenuIds)>1
 3         begin     
 4           
 5           DECLARE @PMenuId INT;
 6           SET @PMenuId=LEFT(@PMenuIds,CHARINDEX(',',@PMenuIds)-1);                                          
 7           
 8           --得到一个RightId,插入
 9           INSERT INTO RoleMenu(RoleCode,MenuID,Valid,CreatorID,CreateTime,UpdateEmployeeID,UpdateTime,IsParentNode)VALUES(@Code,@PMenuId,@Valid,@UpdateEmployeeID,GETDATE(),@UpdateEmployeeID,GETDATE(),1);
10                         
11           
12           --取到一个,删除一个
13           SET @PMenuIds=STUFF(@PMenuIds,1,CHARINDEX(',',@PMenuIds),'');
14          print @PMenuIds;
15         end            
16         INSERT INTO RoleMenu(RoleCode,MenuID,Valid,CreatorID,CreateTime,UpdateEmployeeID,UpdateTime,IsParentNode)VALUES(@Code,@PMenuIds,@Valid,@UpdateEmployeeID,GETDATE(),@UpdateEmployeeID,GETDATE(),1);
17         

 

posted @ 2013-10-16 12:38  Piero's  阅读(380)  评论(0编辑  收藏  举报