T-SQL 实现 Split 的方法,有需要的朋友可以参考下。
DECLARE @list VARCHAR(100), @cnt INT, @idxStart INT, @idxEnd INT
DECLARE @sites TABLE(id INT)
SET @list = '23, 34, 44, 56, 78';
--SET @list = '23';
SET @list = replace(@list, ' ', '')
IF(RIGHT(@list, 1)<>',')
SET @list = @list + ','
SET @cnt = len(replace(@list, ',', ',,'))-len(@list);
SET @idxStart = 0
SET @idxEnd = 0
WHILE @cnt > 0
BEGIN
SET @idxEnd = charindex(',', @list, @idxStart)
INSERT INTO @sites VALUES(convert(INT, substring(@list, @idxStart, @idxEnd-@idxStart)));
SET @idxStart = @idxEnd + 1
SET @cnt = @cnt - 1
END
SELECT * FROM @sites;
其实很简单,应该也比较好理解。
附1:自个写的,也分享下
附2:
这个方法判断 个数 高!