Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Split text every 250 characters and save
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

3 Posts

Posted - 11/30/2012 :  08:48:14  Show Profile  Reply with Quote

I have a column with long text, which I would like to split into columns text1, text2, etc by making a split every 250 characters. Then I would like to save text1, text2, etc together with one other variable as a new table. I've tried to write a script (I guess I'll just need 2 lines really?) with which I can implement that in SQL Browser, but haven't succeeded so far. Would anyone know how to do this?
Thanks so much, JZ

Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 11/30/2012 :  08:59:44  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
;with ce as
select i=1, s = substring(str,1,250), id from tbl
union all
select i=i+1, s = substring(str,(i-1)*250+251,250), id from tbl t join cte c on c.var = t.var where len(str) >= ,(i-1)*250+251
insert newtbl
select var, seq = i, str
from cte

You can pivot this if you want it in columns but you would then need a maximum size for the string.

Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/30/2012 :  09:04:50  Show Profile  Reply with Quote
Another approach, ion case you are really on SQL 2000 and don't have CTE's available to you
DECLARE @x VARCHAR(255)= 'abcdefghkijlmn';

DECLARE @chunksize INT = 3; -- change to what you want
	[type] = 'P'
	AND @chunksize*number <= LEN(@x);

Edited by - sunitabeck on 11/30/2012 09:05:24
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000