Showing posts with label newline. Show all posts
Showing posts with label newline. Show all posts

Monday, March 12, 2012

How to add newline in column of type nvarchar

Hi,
I want to add a newline in a content of sql column (using t-sql and not asp.net textbox) so when content is being rendered in a .net textbox I get separate rows, so instead
col1 col2 col3
I woule like to have
col1
col2
col3
Thanks

You can use CHAR(13) to insert a carriage return into the string. e.g.

INSERT INTO MyTable (MyStringColumn) VALUES('My name is'+CHAR(13)+'Colin Mackay')
See also SQL Server Books-On-Line:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_6xte.asp
Does this help?

|||Yes, that's it, thanks

Wednesday, March 7, 2012

How to add a newline sequence

I have a SQL 2005 stored procedure to generate an email when passed parameters such as receipient, subject etc

One of the paramteres passed to it is @.body which is the body text of the message. I want to be able to add a couple of blank lines and then some footer information. This is working right now except I can't find the right way to add newlines into the string within the store procedure, so my footer information just tags right on after the bodytext.

I have tried \n but that literally adds the two characters \ and n

Can anyone advise how to generate newlien sequences in T-SQL.

Regards

Clive

Use the CHAR function e.g. CHAR(13) + CHAR(10)

Seehttp://doc.ddart.net/mssql/sql70/ca-co_4.htm