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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trim whitespace

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2005-03-04 : 06:26:20
Morning all

Is there a method of trimming whitespace within a field value (not rtrim or ltrim). For example, say I have a field:

000012032005 BLAH99302727484 234249##0093948 9877665

And i want to trim the white space underlined in red. Is that possible?

Thanks

Hearty head pats

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2005-03-04 : 06:50:42
Quite easy actually:

SELECT REPLACE('000012032005 BLAH99302727484 234249##0093948 9877665', ' ', '')

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2005-03-04 : 06:52:08
Oh wait...ony the last whitespace?

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2005-03-04 : 06:58:41
Yeah, just the two last spaces on the right??

Hearty head pats
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-03-04 : 07:24:33
declare @s varchar(2000)
select @s = '000012032005 BLAH99302727484 234249##0093948 9877665'
select stuff(@s, len(@s) - charindex(' ',reverse(@s))+1, 1, '')


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2005-03-04 : 07:38:24
Greeat! Might take me a while for me to decipher, but I always get there in the end!

Ta muchly!

Hearty head pats
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2005-03-04 : 08:11:20
I don't suppose you could explain a bit about what is going on in that query - it works great, but I would like to be able to understand what is happening in each part. Sorry to be demanding!

Hearty head pats
Go to Top of Page
   

- Advertisement -