Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

white spaces

Status
Not open for further replies.

deddleston

Programmer
Oct 4, 2002
43
0
0
GB
How do you remove white spaces/carriage returns from a given string (end of).

pls give an example if you can.

Thanks M$ arn't the only option!
 
You can use the RTRIM function to strip trailing blanks, however I don't think it will work for carriage returns.

Code:
str1 = 'this is a string       '
RTRIM(str1) = 'this is a string'

(You can use LTRIM to strip leading blanks too). --James
 
Ok, i'm using ms sql server 2000, dunno if it makes a difference. but it say's "incorrect sytax near '='" M$ arn't the only option!
 
Deddleston, I think your understanding is not there. To see example working,

DECLARE @str1 AS varchar(30)
SET @str1 = 'this is a string '
SELECT RTRIM(@str1)
 
dammit.... i missed of the select!!!!

DECLARE @str1 varchar(60)
SET @str1 = 'this is a string '
RTRIM(@str1)

thanx for your help M$ arn't the only option!
 
How would i take out carriage returns in the middle of a string? leaving the white spaces?? M$ arn't the only option!
 
Try using the REPLACE function:

Code:
SELECT REPLACE(str1, CHAR(13), '')

(13 is the ASCII value of a carriage return). --James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top