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
 \n in text field, how to return

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-05 : 12:08:03
I have a text field that contains text with linefeed ( hello\n\Jill\nGood Day ) as example. However when I use the .NET framework to return the field I am only getting only a part of the field back and in fact part of the string between the \n was also truncated. I have used a datatable and a scalar query. { sqlScalar = command.ExecuteScalar(); } Ideas ??? Thanks

andrewcw

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-05 : 12:16:34
REPLACE(col,'\n','~')


????

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-05 : 12:22:45
Either I dont understand the answer or I did not explain the situation.
Whenever I issue a query against the field, I only get a portion of the field back.

Are you suggesting a replace the \n in the fields by some other delimiter - before pulling it. Certainly I can have a magic key like that. Also just as much sense might be adding additional fields for each line.

But before I go to either of those paths, I'd like to confirm that \n in a field is terminal. You can put them in, but cant get them out... is that true ???

andrewcw
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-05 : 12:26:53
What version of SQL server are you working with?

Do you have SQL Server Client Tools installed?

Do you know how to write T-SQL Commands?

What are you trying to do? Export Data? Obtain a Result set?

The REPLACE function would replace the value for you, in either a SELECT or an update if you so choose.

Post the table DDL as well



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-05 : 12:52:49
Thanks for clarifying how thge replace would be used. I am using the
I have SQL 2005. I did not realize the replace would be imbedded in the SQL statement.
And, I was looking to just pull the field { export?} with a query & not redesign the table or the field contents - esp since someone else may be entering that data.

But I am still unclear.. this is my simple query:

SELECT TitleDescription
FROM dbo.PFIChartData
WHERE (USPName = 'dbo.usp_PFISumProcessIssuesByLN')

I tried this : SELECT REPLACE(TitleDescription, '\n', '~') AS Expr1
FROM dbo.PFIChartData
WHERE (USPName = 'dbo.usp_PFISumProcessIssuesByLN')

But only got the same result.

{ TitleDescription} is the field with the \n's. I have sql server management but typically use my window for server explorer for Visual Studio ).


andrewcw
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-05 : 13:03:15
Please show us some sample data from both of your selects



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-06 : 01:14:22
Yes Here is the field:
Not caused by real problems.\nIncludes failed repeats of same procedure. This number is not the number of retries or attempts. \nChart does not distinguish if a few procedures failed multiple times, or multiple procedures failed a few times.

All I have been able to retrieve is "Includes repeats of same procedure"

andrewcw
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-06 : 01:26:29
Ohhhh I must have done something weird. I am embarrassed.
I use Show Tabel Data.
I went back and saw the field somehow was now only "Includes repeats of same procedure" -

I put back the multi line string & the entire string is coming out with the \n attached.
Thanks.

andrewcw
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-10-06 : 01:39:33
OK I think I had this all backwards. I put a string in like this :

Not caused by real problems.\nIncludes failed repeats...

Well I get the \n out too. When I examine it inside code its "\\n" which makes sense.
I will have to test if its possible to copy a line feed in instead of what I did ... or anyone can suggest what they have done.

Thanks

andrewcw
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-10-06 : 02:51:08
Not sure if this works for you but could you try using CHAR(13)? I guess something like this:

SELECT REPLACE(mycolumn, '\n', CHAR(13))

If you run set your query output as text in SSMS this query will at least be displayed in two lines:

SELECT 'lumbago' + char(13) + 'rules' AS value

- Lumbago
http://xkcd.com/327/
Go to Top of Page
   

- Advertisement -