2

Using: t-SQL, SSMS 2008, Excel 2010

Background: I have a SQL query that I've embedded into an Excel workbook via Connection that the end user can refresh. This query returns a column with a long string of sentences, basically a paragraph (this column's datatype is flexible).

What I Am Trying To Do: I would like each sentence of the paragraph to start on a new line in the Excel cell that it's in.

Example of UNDESIRED formatting: enter image description here

Example of DESIRED formatting: enter image description here

What I've Tried: I've tried adding the CHAR(13) linebreak to the SQL query. It correctly prints the paragraph with the desired line breaks in SSMS, but it doesn't transfer over to Excel, when the workbook is refreshed.

3
  • IS the excel document formatted to allow wrapping of text? and do you need char(10)+char(13)? (vbcrlf) (carrige return line feed) Commented May 31, 2016 at 18:00
  • @xQbert Let me try each of these now, and I will report back Commented May 31, 2016 at 18:01
  • @xQbert Looks like that was it! It was a combination of both enabling text wrapping and adding CHAR(10) to the CHAR(13) that I already had. If you'd like to make your comment an answer, I'd be happy to accept. Commented May 31, 2016 at 18:04

1 Answer 1

2

I'm not sure if you really need the wrapping of text. But I'm pretty sure you need both char(10) and char(13) carriage return and line feed (vbcrlf) equivalent.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you much for your answer!! Btw, I tested it without wrapping and it did NOT work.
For anyone who reads this answer, here is an example of how it will work, assuming you have text wrap enabled in Excel: select 'This is a paragraph.' + CHAR(10) + CHAR(13) + 'It contains many sentences.' + CHAR(10) + CHAR(13) + 'I would like each sentence to start on a new line w/in the cell.'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.