Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiline text in varchar(MAX) field

I have created varchar(MAX) field as memo field. Unfortunately I do not find a way how to add multiline text into such field using MS SQL Server Management Studio. If I use copy/paste of multiline text only first line of multiline test is inserted into varchar(MAX) field.

like image 469
Tomas Avatar asked Jul 29 '11 11:07

Tomas


People also ask

How do I insert multiple lines of text in SQL Server?

You can use REPLACE('Line1@Line2@Line3', '@', CHAR(13) + CHAR(10)) , for example. Show activity on this post. All+Enter jums to next records.

How many characters does VARCHAR max allow?

The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

What is the difference between text and VARCHAR Max?

Some Differences Between VARCHAR and TEXT The VAR in VARCHAR means that you can set the max size to anything between 1 and 65,535. TEXT fields have a fixed max size of 65,535 characters. A VARCHAR can be part of an index whereas a TEXT field requires you to specify a prefix length, which can be part of an index.

Should you always use VARCHAR Max?

CHAR, VARCHAR, and VARCHAR(MAX) CHAR columns should be used for columns that vary little in length. String values that vary significantly in length and are no longer than 8,000 bytes should be stored in a VARCHAR column. If you have huge strings (over 8,000 bytes), then VARCHAR(MAX) should be used.


2 Answers

As you observe, if you paste in multi-line text only the first line is inserted, instead paste the text into an update statement and run that;

update T set fld =
'aaa
sss
ddd'
where ...

(You need to SELECT in results to text mode to observe the lines, in the grid view they appear as double-spaces)

like image 151
Alex K. Avatar answered Sep 17 '22 15:09

Alex K.


You can use REPLACE('Line1@Line2@Line3', '@', CHAR(13) + CHAR(10)), for example.

like image 20
User Avatar answered Sep 19 '22 15:09

User