beagreatman

导航

 
 1 DECLARE @T_test TABLE (newcode NVARCHAR(100))
 2 DECLARE @str VARCHAR(MAX)
 3     ,@split VARCHAR(10)
 4     ,@start INT
 5     ,@end INT
 6     ,@newcode VARCHAR(10)
 7 
 8 SET @str = '1,2,3,4,5,6,7,8'
 9 SET @split = ','
10 SET @end = 1
11 SET @start = 0
12 
13 WHILE (@end > 0)
14 BEGIN
15     SET @end = CHARINDEX(@split, @str, @start + LEN(@split))
16 
17     IF @end = 0
18     BEGIN
19         SET @newcode = SUBSTRING(@str, @start + 1, LEN(@str) - @START)
20     END
21     ELSE
22     BEGIN
23         SET @newcode = SUBSTRING(@str, @start + 1, @end-@start-1)
24     END
25 
26     SET @start = @end
27 
28     INSERT INTO @T_test (newcode)
29     VALUES (@newcode)
30 END
31 
32 SELECT *
33 FROM @T_test

 

posted on 2016-11-14 16:51  BeAMan  阅读(1560)  评论(0编辑  收藏  举报