tsql - SQL Server: split long text into multiple lines with max # of characters per line -
is there function in sql server splits long text multiple lines?
say have 1,000 characters , need split text multiple lines max of 80 characters per line, can split @ spaces not in middle of word?
thanks.
there's not built in split function, can use multiple substrings/charindex, like:
declare @fieldname varchar(max) = 'lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industrys standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen book. has survived not 5 centuries, leap electronic typesetting, remaining unchanged. popularised in 1960s release of letraset sheets containing lorem ipsum passages, , more desktop publishing software aldus pagemaker including versions of lorem ipsum.' select substring(@fieldname,1,charindex(' ',@fieldname,70)-1) ,substring(@fieldname,charindex(' ',@fieldname,70)+1,charindex(' ',@fieldname,140)-charindex(' ',@fieldname,70)) ,substring(@fieldname,charindex(' ',@fieldname,140)+1,charindex(' ',@fieldname,210)-charindex(' ',@fieldname,140))
demo: sql fiddle
or search for/create udf, seem plenty out there.
could use substring/charindex method in cte , pivot results too.
Comments
Post a Comment