DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to split CSV list inline fast?

The following Microsoft SQL Server T-SQL database script in SSMS Query Editor uses recursive CTE to split a CSV list inline fast.

 
-- T-SQL delimited list splitter - split string list
DECLARE @CSV varchar(128)
      = 'Seattle Steel Structures,720 4th Avenue,,,Kirkland,WA,98233,
      425-729-5600,425-729-5601';
 
 
;WITH ctecsvsplit
     AS (SELECT Element = Left(@CSV,NULLIF(Charindex(',',@CSV),0) - 1),
                runningcsv = Stuff(@CSV + ',',1,Charindex(',',@CSV),'')
         UNION ALL
         SELECT Convert(VARCHAR(128),Left(runningcsv,Charindex(',',runningcsv) - 1)),
                Stuff(runningcsv,1,Charindex(',',runningcsv),'')
         FROM   ctecsvsplit
         WHERE  runningcsv <> '')
SELECT Element
FROM   ctecsvsplit
GO
/*
Element
Seattle Steel Structures
720 4th Avenue
 
 
Kirkland
WA
98233
        425-729-5600
425-729-5601

*/

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE