SET NOCOUNT ON DECLARE @splitString VARCHAR(MAX) = 'ab,cd,efg, hello world!'; --需要被拆分的字符串 DECLARE @separator VARCHAR(10) = ','; --分隔符 DECLARE @CurrentIndex int; DECLARE @NextIndex int; DECLARE @ReturnText nvarchar(max); SET @CurrentIndex = 1; WHILE(@CurrentIndex<=len(@SplitString)) BEGIN SELECT @NextIndex=charindex(@Separator,@SplitString,@CurrentIndex); IF(@NextIndex=0 OR @NextIndex IS NULL) BEGIN SELECT @NextIndex=len(@SplitString)+1; END SELECT @ReturnText=substring(@SplitString,@CurrentIndex,@NextIndex-@CurrentIndex); SELECT @ReturnText --打印拆分结果 SELECT @CurrentIndex=@NextIndex+1; END