As webfred sais -- this is a lot better to do in the front end.Here's one way to do it in the back end though! -- This is a dirty hack and will be limited to 32767 recursions which is to strings of less than 3276700 characters.NB:This is a a really bad thing to do in the db and there are probably much better ways to do it if you did have to but I wans interested in shoe horning a recursive CTE to do the job!DECLARE @foo TABLE ( [ID] INT , [value] NVARCHAR(MAX) )INSERT @foo ([Id], [value]) SELECT 1, 'aslkdjkjfa;sdlgkjal;djkg;aldgjka;erg agna;odfbj;arji;hjaer;gadfg;adfngadfnghladfjgha;df jv;av;aerjg;aeriojg;aj;dknvadfnkgbdfjgjae;origj;adjg;adflkg;adfnkb;adfnbafd;ogj;aeroijg;aerg;dfjkbnladfkjbnafdhgo;ierg;oamgl;dfknv;akdfbnladfigh;erjg;aejg;kadfjbgkl;dflnb;adfbasdfasdfasdfawefasdgasdhadfhafdhddh'UNION SELECT 2, 'This is a lot of text that hopefully adds up to more that 100 characters. This is a lot of text that hopefully adds up to more that 100 characters. This is a lot of text that hopefully adds up to more that 100 characters. This is a lot of text that hopefully adds up to more that 100 characters. This is a lot of text that hopefully adds up to more that 100 characters. This is a lot of text that hopefully adds up to more that 100 characters.'UNION SELECT 3, 'Not very much text here'SELECT [ID] , LEN([value])FROM @foo;WITH splitter AS (SELECT f.[Id] AS [fooID] , SUBSTRING(f.[value], 1, 100) AS [Text] , 100 AS [pointer] , 1 AS [lineNo] , 0 AS [backPointer]FROM @foo fUNION ALL SELECT f.[ID] , SUBSTRING(f.[value], s.[pointer] + 1, 100) , s.[pointer] + 100 , s.[lineNo] + 1 , s.[backPointer] + 1FROM @foo f JOIN splitter s ON s.[fooID] = f.[ID] AND s.[lineNO] - 1 = s.[backPointer] AND s.[pointer] < LEN(f.[value]))SELECT [fooID], [lineNo], [text], LEN([text]) FROM splitterORDER BY [fooId] , [lineNo]
Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION