473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Remove the last carriage return and line feed from sql text field

I am trying to write a user defined function that will allow me to
strip off the last carriage return and line feed from a text field.
We have address fields stored in a text field for our ERP system and
some of them have an extra carriage return and line feed at the end of
them. This causes havoc when we sync between our ERP system and CRM
system. If anyone knows a way to solve this problem the help would be
appreciated.

Examples:
Existing Text field with CR:

1234 Blah Street<CR>
Suite 2345<CR>

Corrected Text field:

1234 Blah Street<CR>
Suitr 2345

Jun 12 '07 #1
4 27788
(wh*********@gmail.com) writes:
I am trying to write a user defined function that will allow me to
strip off the last carriage return and line feed from a text field.
We have address fields stored in a text field for our ERP system and
some of them have an extra carriage return and line feed at the end of
them. This causes havoc when we sync between our ERP system and CRM
system. If anyone knows a way to solve this problem the help would be
appreciated.

Examples:
Existing Text field with CR:

1234 Blah Street<CR>
Suite 2345<CR>

Corrected Text field:

1234 Blah Street<CR>
Suitr 2345
SELECT substring(col, 1,
len(str) - CASE WHEN str LIKE '%' + char(13)
THEN 1
ELSE 0
END)

1) I've taken you by the word that the character at the end is precisely
CR. You may find that it is LineFeed (char(10)) or CR+LF.

2) I did not take you by the word on the data type, but assumed that
when you said "text" you in fact mean a varchar column. If the data
type actually is text, I don't know for sure if the above will
work.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 12 '07 #2
On Jun 12, 5:14 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
(whitej77...@gmail.com) writes:
I am trying to write a user defined function that will allow me to
strip off the last carriage return and line feed from a text field.
We have address fields stored in a text field for our ERP system and
some of them have an extra carriage return and line feed at the end of
them. This causes havoc when we sync between our ERP system and CRM
system. If anyone knows a way to solve this problem the help would be
appreciated.
Examples:
Existing Text field with CR:
1234 Blah Street<CR>
Suite 2345<CR>
Corrected Text field:
1234 Blah Street<CR>
Suitr 2345

SELECT substring(col, 1,
len(str) - CASE WHEN str LIKE '%' + char(13)
THEN 1
ELSE 0
END)

1) I've taken you by the word that the character at the end is precisely
CR. You may find that it is LineFeed (char(10)) or CR+LF.

2) I did not take you by the word on the data type, but assumed that
when you said "text" you in fact mean a varchar column. If the data
type actually is text, I don't know for sure if the above will
work.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -

- Show quoted text -
I did mean that the data type was actually text which is what is
probably causing the most problem.

Jun 15 '07 #3
(wh*********@gmail.com) writes:
On Jun 12, 5:14 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
> (whitej77...@gmail.com) writes:
SELECT substring(col, 1,
len(str) - CASE WHEN str LIKE '%' + char(13)
THEN 1
ELSE 0
END)

I did mean that the data type was actually text which is what is
probably causing the most problem.
So did my SELECT work for you?

I can spot one change that is needed: use datalength() rather than
len(), as len() does not work past the 8000-character limit.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 15 '07 #4
On Jun 15, 5:08 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
(whitej77...@gmail.com) writes:
On Jun 12, 5:14 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
(whitej77...@gmail.com) writes:
SELECT substring(col, 1,
len(str) - CASE WHEN str LIKE '%' + char(13)
THEN 1
ELSE 0
END)
I did mean that the data type was actually text which is what is
probably causing the most problem.

So did my SELECT work for you?

I can spot one change that is needed: use datalength() rather than
len(), as len() does not work past the 8000-character limit.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Well I modified it slightly to get it to work but thank you for the
help. Here is what I used:

substring(fmstreet, 1, datalength(fmstreet) - CASE WHEN fmstreet LIKE
'%' + char(13) + char(10) THEN 2 ELSE 0 END)

Thanks again.

Jun 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Canes_Rock | last post by:
The information posted at: ...
6
by: Andrew | last post by:
I have created a program that downloads a web page and then performs some text processing on it . The problem is in the text processing , every line (in the downloaded txt file ) ends with a...
3
by: David N. | last post by:
Hi All, I spent too much time on trying to get the CrLf into a string, which contains embedded SQL statements that can be executed by the SQLClient.SqlCommand. Note that these SQL statements...
2
by: Torsten Zachert | last post by:
I would like to insert some text with embedded carriage return/line feed into a MS Access text field with OleDb and C# ADO.NET. I tried to use "\n" in combination with "\r". If I display the input...
11
by: TheRain | last post by:
Hi, I am trying to append a carriage return to my string using the string builder class, but when I do this the string ends up containing "13". I tried this multiple ways like so ...
3
by: Gillian Steele | last post by:
I'm trying to import data into a memo field by running an append query. The data is to be imported as if it was entered with separate lines in the memo field. I have tried inserting chr(13)s...
4
by: coolguyraj | last post by:
Hi. I have form that has a text box. I want insert unformatted text into the database. Even if the user gives an carriage return or New line feed in the database it should be stored as on single...
11
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
1
by: jollyroger | last post by:
I have searched the web forums, and can't seem to find an answer to this particular problem I have. In an excel sheet, cells in one column have formatted text in the "wrapped" cells. For many of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.