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.
| Author |
Topic |
|
jcb267
Constraint Violating Yak Guru
291 Posts |
Posted - 2010-10-15 : 12:36:09
|
| How do you remove leading and trailing blanks from a string? |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-15 : 12:40:11
|
| Use ltrim and rtrim.CODO ERGO SUM |
 |
|
|
jcb267
Constraint Violating Yak Guru
291 Posts |
Posted - 2010-10-15 : 12:42:12
|
How do you use them together? I can use them one at a time.....quote: Originally posted by Michael Valentine Jones Use ltrim and rtrim.CODO ERGO SUM
|
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2010-10-15 : 15:12:07
|
| ltrim(rtrim(YourValue))________________________________________________If it is not practically useful, then it is practically useless.________________________________________________ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-10-16 : 02:53:46
|
| I would add to Brett's suggestion:UPDATE table SET col = RTRIM(LTRIM(col))WHERE col <> RTRIM(LTRIM(col))to cut down the number of updates / amount of logging, particularly on a large table |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2010-10-18 : 12:49:17
|
quote: Originally posted by X002548 ahhhh...the oppie said s/he wants to remove them from a column..
S/he did?All I saw was 'How do you remove leading and trailing blanks from a string?"Nevertheless, in the spirit of the thread, I will improve on Kristen's improvement of Brett's Improvement of my implementation of Michael's solution:Use [DeadHorse]GOUPDATE table SET col = RTRIM(LTRIM(col))WHERE col <> RTRIM(LTRIM(col)) We would not want this run on just any database the OP happens to have set as their default, would we?________________________________________________If it is not practically useful, then it is practically useless.________________________________________________ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-10-18 : 13:42:11
|
I wonder ifWHERE Col LIKE ' %'OR Col LIKE '% ' would be more efficient?? |
 |
|
|
|
|
|