How to generate insert script from sql server with line breaks in data

I have data with line feeds as below how can I generate the insert scripts with line break

Mytable
----------
Field1                      Desc
1                              This is a tes1a<CR>
                                This is a tes1b<CR>
                                This is a tes1
2                              This is a tes2a<CR>
                                This is a tes2b
3                              This is a tes3a<CR>
                                This is a tes3b<CR>
                                This is a tes3c
Bharat GuruAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
By using line breaks?!

DECLARE @Sample TABLE
    (
      ID INT ,
      Payload NVARCHAR(64)
    );

INSERT  INTO @Sample
VALUES  ( 1, N'This is a tes1a
This is a tes1b
This is a tes1' ),
        ( 2, N'This is a tes2a
This is a tes2b' ),
        ( 3, N'This is a tes3a
This is a tes3b
This is a tes3c' );

SELECT  S.Payload ,
        S.ID
FROM    @Sample S;

Open in new window


Just use Results to Text in SSMS.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott PletcherSenior DBACommented:
Carriage Return = CHAR(13)
Line Feed = CHAR(10)

Typically the LF char is more critical, but if you just want a CR you can do this:

'This is a tes1a' + CHAR(13) + 'This is a tes1b' + CHAR(13) + 'This is a tes1'
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Bharat, do you still need help with this question?
0
Bharat GuruAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.