DECLARE @splitchar nvarchar(1)
SET @splitchar=‘,’
SET @userId=@userId+@splitchar
WHILE CHARINDEX(@splitchar,@userId)>0
BEGIN
SET @temp=SUBSTRING(@userId,1,CHARINDEX(@splitchar,@userId)-1)
IF(LEN(@temp)>0)
BEGIN
PRINT(@temp)
DELETE from TB_user WHERE user_id =@temp;
END
SET @userId=RIGHT(@userId,LEN(@userId)-CHARINDEX(@splitchar,@userId))
PRINT(@userId)
END
END
用到的函数有:CHARINDEX();LEN();RIGHT();SUBSTRING()
charindex(expression1 , expression2 )表示:
从expression2字符串中指定的位置处开始查找是否包含expression1字符串。如果能够从expression2字符串中查找到expression1字符串则返回expression1在
expression2出现的位置;反之,返回0
LEN(expression1 )表示:返回expression1 的长度;
RIGHT(expression,number)表示:从expression右边开始ÿ