字符串分解


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
DECLARE @Value AS VARCHAR(20) = 'ABCC' 
DECLARE @NoOfChars AS INT = LEN(@Value)
DECLARE @Permutations TABLE (Value VARCHAR(20)) 
 ;

WITH NumTally
AS (
 --Prepare the Tally Table to separate each character of the Value.
 SELECT 1 Num

 UNION ALL

 SELECT Num + 1
 FROM NumTally
 WHERE Num < @NoOfChars
 ),
Chars
AS (
 --Separate the Characters
 SELECT Num,
  SUBSTRING(@Value, Num, 1) Chr
 FROM NumTally
 )
 SELECT *
 FROM Chars