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
 Trimming spaces

Author  Topic 

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-03-09 : 14:28:50
I need to trim what looks like two spaces from a field.

Example:

" 601274" needs to be "601274". Does anyone know the syntax?+

X002548
Not Just a Number

15586 Posts

Posted - 2006-03-09 : 14:33:59
LTRIM or BOL



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

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-03-09 : 15:08:15
So it will be LTRIM(AccountID)???
Go to Top of Page

Tahsin
Starting Member

34 Posts

Posted - 2006-03-09 : 15:10:31
Yes, if that's the name of your column. LTRIM will remove all spaces in the front and RTRIM will remove trailing spaces.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-03-09 : 15:11:08
Yes


DECLARE @account varchar(50)
SELECT @account = ' 601274'

SELECT '"' + @account + '"', '"' + LTRIM(@account) + '"'





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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-09 : 15:22:00
quote:
Originally posted by gemispence

So it will be LTRIM(AccountID)???



Why don't you try it rather than asking? Also, you should do some reading on all of the character functions available in T-SQL in SQL Server Books Online as LTRIM would have been fairly quick to find in BOL.

Tara Kizer
aka tduggan
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-03-09 : 15:30:28
I did try it and it did look at the documentation. The problem was that I was using [] instead of (). This is a beginner's forum so why don't you cut us some slack. Thanks. :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-09 : 15:38:19
With 70 posts already, it's hard to believe that you'd still be a newbie to SQL Server. But feel free not to read my posts if I'm not giving any slack.

Tara Kizer
aka tduggan
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-03-09 : 15:55:09
With pleasure. How about you not respond to any of my posts either? Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-09 : 15:56:32
I can't keep track of who wants me to respond and who doesn't.

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -