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
 Remove leeding blanks in string

Author  Topic 

maevr
Posting Yak Master

169 Posts

Posted - 2009-11-04 : 10:29:17
The string i want to remove the blanks looks like the one below. I have tried LTRIM but i cannot make it work.

The characters before is blanks ' '.
Output:
' test test test'

expected output:
'test test test'

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-04 : 10:39:12
select ltrim(' test test test')
should give 'test test test'

If not then maybe there are some special chars in your columns?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

maevr
Posting Yak Master

169 Posts

Posted - 2009-11-05 : 00:43:27
How can I find out with special chars that exists in a given string?

The strange is that i tried replace(col1, ' ', '') and then It removed all blanks in the string, but I only want to remove the leeding.
Go to Top of Page

maevr
Posting Yak Master

169 Posts

Posted - 2009-11-05 : 01:58:01
I have checked and the ascii is 32 but the query does not seem to work:

select ltrim(col1) where substring(col1, 1, 1) = char(32)
from table1
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 04:24:32
If it was char(32) then there could not be a problem because the trim command would work...
You have to search for other characters (for example char(0) to char(31)) and delete them.

I will come back...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-05 : 04:34:23
This will examine the first character of you column in the table:

select ascii(left(your_column,1)) as specialcharAsciiCode,*
from your_table
where patindex('%['+char(0)+'-'+char(31)+']%',your_column) > 0




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -