views:

5509

answers:

9

In the "datagrid" view of an open table of data, how can I type a new line character into an nvarchar field directly in SSMS?

Is there an alt code?

A: 

this works for me (View results as text -- results as grid hides the newlines)

select '

a 

b

'
Jimmy
Umm... What is this supposed to do?
Robert Harvey
+1 Robert Harvey -- I don't get it either.
Ronnie Overby
I believe that the example given above was to show that the linke breaks in the quoted string will be retained in the string in the results of the Select statement.Although I don't think it actually answers the original question because that's not how to type a newline character into the datagrid of an open table of data.
Adam Porad
yeah, I misinterpreted the question.
Jimmy
A: 

I use INSERT 'a' + Char(10) + 'b' INTO wherever WHERE whatever

Dour High Arch
That's not the question. I will edit to make it clearer.
Robert Harvey
Thanks, Robert.
Ronnie Overby
+1  A: 

Ronnie,

The data grid appears to be swallowing any attempts to paste a newline character, including the use of ALT+010. Microsoft does not list any shortcut keys that would help. The usual suspects

<ctrl>enter, 
<alt> enter, 
<ctrl><alt> enter, 
<shift> enter, etc

don't work, as you pointed out.

For the record, if you are doing web development, the linefeeds will not show up in the browser anyway (they are interpreted as extra whitespace, and are ignored). I had to replace line feed with

<br>

everywhere I wanted a line break to show up in the browser (text areas will accept line feeds as usable input).

Even if you could insert a line break, I don't think the data grid view in SSMS is capable of displaying it.

Robert Harvey
It can display it as a square. I was able to paste the square from another record, but I haven't found a way of typing it.
Ronnie Overby
AFAIK that's the only way to do it.
Robert Harvey
However, that's certainly better than nothing, in a pinch. I would certainly loathe the prospect of writing SQL statements just to insert a line feed, as others have suggested. I know you can do it, it just grates.
Robert Harvey
Raj's solution works.
Robert Harvey
@Robert Harvey - Not for me.
Ronnie Overby
+6  A: 

You can't.

Use a "new query" window instead, and do a manual update:

UPDATE mytable
SET textvalue = 
'This text
can include
line breaks'
WHERE rowid = 1234
BradC
A: 

You're talking about right-clicking on a table and selecting "Edit Top 50 Rows", right?

I tried [Ctl][Enter] and [Alt][Enter], but neither of those works.

Even when I insert data with CR/LF (using a standard INSERT statement), it shows up here in a single line with a rectangle representing the control codes.

Rob Garrison
But that's just a visual issue in SSMS. The CR/LF is really stored there.
BradC
+1  A: 

You can prepare the text in notepad, and paste it into SSMS. SSMS will not display the newlines, but they are there, as you can verify with a select:

select *
from YourTable
where Col1 like '%' + char(10) + '%'
Andomar
I've tried this also. It doesn't work for me.
Ronnie Overby
I'm using SSMS 2008, maybe you have an older version?
Andomar
+1  A: 

If you are trying to enter data directly into the table in grid view (presumably Right Click TableName and Select Open Table), then you can enter your unicode text string and wherever you want a carriage return just type 13 with the alt key pressed in the numeric keypad.

That would be Alt+13. This works only from the numeric keypad and does not work with the number keys on the top of the keyboard. The carriage return will be stored as a square

Raj
That stores a music symbol: ♪
Ronnie Overby
Are you sure you're in SSMS? I'm using SSMS Express. Is there really a behavioral difference between the two programs?
Robert Harvey
+1  A: 

Try using MS Access instead. Create a new file and select 'Project using existing data' template. This will create .adp file.

Then simply open your table and press Ctrl+Enter for new line.

Pasting from clipboard also works correctly.

Pavel Chuchuva
A: 

either char(13) or char(10) would work. but it is recommended to use char(13) + char(10)

  • char(13) = \n - new line
  • char(10) = \r - go to the beginning of the line
tecfield