0

i have SQL SELECT query with long string, example:

SELECT RTRIM(CAST(DNH_INFO AS VARCHAR(150)))

'_This is _a very _long string _separated _with underline'

as i result a want to break lines by underline but still remain the same string, exmaple:

'_This is

 _a very

 _long string

 _...'

Is there any SQL function with which i can solve this problem?

Thanks for help!

trincot
  • 317,000
  • 35
  • 244
  • 286
makaroN
  • 305
  • 1
  • 4
  • 16

1 Answers1

1

@makaroN you can replace the space and underline with a LineFeed and Carriage Return and then re-add the underline. Alternatively you can use just the carriage Return (char(13) or reverse char(13) + char(10) if you do not need the extra line space. See the example below.

SELECT REPLACE('_This is _a very _long string _separated _with underline', 
               ' _', char(10) + char(13) + '_')

p.s if executing in management studio you may want to select Results to Text to immediately see the format.

trincot
  • 317,000
  • 35
  • 244
  • 286