Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 storing new line characters.

Author  Topic 

chris_j_pook
Starting Member

2 Posts

Posted - 2007-06-07 : 11:06:06
Hi !

Im having trouble storing newline characters in my varchars so that when I INSERT something like this ...

"one
two
three"

... it doesnt get displayed as "onetwothree" when I get it back out of the database ?

How can I get this kind of functionality ?

Many thanks for your replies, I'm sure this must be pretty simple. Im using SQLServer 2005 and PHP.

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2007-06-07 : 11:43:23
bit confused

you want them displayed as onetwothree
or you do NOT want them displayed as onetwothree?

seperately is this to be saved in 1 field on 1 record in the databse or 3 seperate records?
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-07 : 11:57:12
The linefeed has to come from your front-end. In .NET I know there is something like textbox1.replacE(Environment.newline,'') etc..and you do the reverse when you display at the front end. DB will store the data the way it receives.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-06-07 : 15:12:34
try someting like:
DECLARE @T Table (a VARCHAR(500))

INSERT @T
SELECT 'one' + CHAR(13) + CHAR(10) + 'two' + CHAR(13) + CHAR(10) + 'three'

SELECT *
FROM @T
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-07 : 23:34:56
Why you want format the data while storing...

Formatting very easy to set in the front end and always You have to format whenever you represent to the user.

--------------------------------------------------
S.Ahamed
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-08 : 09:44:47
When you show data in PHP, use newline character there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-08 : 12:18:10
how will the code know where the line breaks were unless the data was stored with line breaks when the data was saved? I think the best way is to use the front end to replace the line breaks with the environment.newline values before saving to the db and replace it back with line breaks before showing it to the user.

Or,
use a rich text editor and save formatted HTML code and let the broser parse it out for you.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-06-08 : 14:09:55
I think we need much more info about what is trying to be done here. My guess is he is trying to stuff multiple values into a single column in a table, which should of course be normalized. We don't know for sure until we get more info.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -