存储过程拆分字符窜

ALTER PROCEDURE [dbo].[P_ComparePrice]
 @siteName varchar(50),
 @goodsId varchar(max)
AS
BEGIN
  DECLARE @splitChar CHAR(1)
  DECLARE @IDS VARCHAR(20)
  SET @splitChar = ','
 
  WHILE(charindex(@SplitChar,@goodsId)<>0)----当分隔符的索引不等于0时 
  BEGIN  
     SET @IDS=SUBSTRING(@goodsId,1,charindex(@splitChar,@goodsId)-1)----取值
    -- print @IDS
   EXEC [P_DeleteRepeatRecord] @siteName,@IDS ----调用存储过程
     SET @goodsId=STUFF(@goodsId,1,charindex(@SplitChar,@goodsId),'')----设置分割后的字符串
  END
 

END

posted @ 2012-03-02 14:48  咸鱼公子  Views(224)  Comments(0Edit  收藏  举报