Corovei Andrei
Corovei Andrei

Reputation: 1668

Inserting \n in sql table column

I would like to insert in a table some pieces of code. For example:

table:

create table  [tbl_cfg](
    [tabid] [int] IDENTITY(1,1) NOT NULL,
    cust_code nvarchar(max) NULL
    ) ON [PRIMARY]


Insert into tbl_cfg(cust_code)
select ' this is the first line
         this is the second line'

My problem is that when I do this, sql automatically flatterns my code i.e. any \n is replaced with spaces.

If I insert it with Edit top 200 rows and I just paste the code, only the first line is inserted.

UPDATE:

In order to test this: select * from tbl_cfg copy the code and paste it in another window

Upvotes: 0

Views: 12851

Answers (3)

asdf_enel_hak
asdf_enel_hak

Reputation: 7650

According my experience about this issue:

Your strings with \n is still in the original format in sql table, but when you do select it is presented in a single line.

However, for example if you put the string to html code, you'll see \n is still there.

Upvotes: 2

aF.
aF.

Reputation: 66757

That's because you aren't seeing the result in text mode.

See this query and view the results with "Results to Text" checked and unchecked.

Upvotes: 0

Related Questions