Home All Groups Group Topic Archive Search About

Left trimming little squares/spaces

Author
2 Mar 2006 9:38 PM
MittyKom
Hi All

I have a table that is populated by an excel plugin. Some of the populated
rows have spaces in front. In Enterprise Manager, they appear with little
squares in front.  I have  been trying to LTRIM the whole column but there is
no change.

This is what i have been executing for a specifc row with these spaces:
update Tbcnt
set firstname = ltrim(firstname)
where contactnumber = 100000

Is there any special way to trim these spaces. Thank you in advance.

Author
2 Mar 2006 10:03 PM
Aaron Bertrand [SQL Server MVP]
Can you find out what they are?
E.g.

SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table

Also, is the only symptom that you see the box in Enterprise Manager, but
the data works fine in the applications that consume it?  If so, just stop
looking at the data in Enterprise Manager -- Query Analyzer is a better
place anyway.  And/or, have Excel trim the data BEFORE it sends it to the
database.





Show quote
"MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
> Hi All
>
> I have a table that is populated by an excel plugin. Some of the populated
> rows have spaces in front. In Enterprise Manager, they appear with little
> squares in front.  I have  been trying to LTRIM the whole column but there
> is
> no change.
>
> This is what i have been executing for a specifc row with these spaces:
> update Tbcnt
> set firstname = ltrim(firstname)
> where contactnumber = 100000
>
> Is there any special way to trim these spaces. Thank you in advance.
>
>
>
>
>
Author
2 Mar 2006 10:20 PM
MittyKom
Hi Aaron

Thank you for the reply. I executed:
SELECT ASCII(SUBSTRING(firstname,1,1)), 
CHAR(ASCII(SUBSTRING(firstname,1,1))) FROM contacthd where  contactnumber =
100000


and the ASCII code came as 10. 

These spaces are causing problems when we mail merge this data and i dont
know how easy it is to trim this data in excel. Right now i have to trim
several tables and i will then work on triming this in excel. Your response
is greatly appreciated



Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> Can you find out what they are?
> E.g.
>
> SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table
>
> Also, is the only symptom that you see the box in Enterprise Manager, but
> the data works fine in the applications that consume it?  If so, just stop
> looking at the data in Enterprise Manager -- Query Analyzer is a better
> place anyway.  And/or, have Excel trim the data BEFORE it sends it to the
> database.
>
>
>
>
>
> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
> > Hi All
> >
> > I have a table that is populated by an excel plugin. Some of the populated
> > rows have spaces in front. In Enterprise Manager, they appear with little
> > squares in front.  I have  been trying to LTRIM the whole column but there
> > is
> > no change.
> >
> > This is what i have been executing for a specifc row with these spaces:
> > update Tbcnt
> > set firstname = ltrim(firstname)
> > where contactnumber = 100000
> >
> > Is there any special way to trim these spaces. Thank you in advance.
> >
> >
> >
> >
> >
>
>
>
Author
2 Mar 2006 10:28 PM
Aaron Bertrand [SQL Server MVP]
UPDATE contacthd
    SET firstname = SUBSTRING(firstname, 2, LEN(firstname))
    WHERE ASCII(SUBSTRING(firstname,1,1)) = 10;



Show quote
"MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
news:BC258672-A921-4C3E-9BEC-C8EE9CC83E01@microsoft.com...
> Hi Aaron
>
> Thank you for the reply. I executed:
> SELECT ASCII(SUBSTRING(firstname,1,1)),
> CHAR(ASCII(SUBSTRING(firstname,1,1))) FROM contacthd where  contactnumber
> =
> 100000
>
>
> and the ASCII code came as 10.
>
> These spaces are causing problems when we mail merge this data and i dont
> know how easy it is to trim this data in excel. Right now i have to trim
> several tables and i will then work on triming this in excel. Your
> response
> is greatly appreciated
>
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
>> Can you find out what they are?
>> E.g.
>>
>> SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table
>>
>> Also, is the only symptom that you see the box in Enterprise Manager, but
>> the data works fine in the applications that consume it?  If so, just
>> stop
>> looking at the data in Enterprise Manager -- Query Analyzer is a better
>> place anyway.  And/or, have Excel trim the data BEFORE it sends it to the
>> database.
>>
>>
>>
>>
>>
>> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
>> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
>> > Hi All
>> >
>> > I have a table that is populated by an excel plugin. Some of the
>> > populated
>> > rows have spaces in front. In Enterprise Manager, they appear with
>> > little
>> > squares in front.  I have  been trying to LTRIM the whole column but
>> > there
>> > is
>> > no change.
>> >
>> > This is what i have been executing for a specifc row with these spaces:
>> > update Tbcnt
>> > set firstname = ltrim(firstname)
>> > where contactnumber = 100000
>> >
>> > Is there any special way to trim these spaces. Thank you in advance.
>> >
>> >
>> >
>> >
>> >
>>
>>
>>
Author
2 Mar 2006 10:43 PM
MittyKom
Thank you so much Aaron. It worked.


Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> UPDATE contacthd
>     SET firstname = SUBSTRING(firstname, 2, LEN(firstname))
>     WHERE ASCII(SUBSTRING(firstname,1,1)) = 10;
>
>
>
> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> news:BC258672-A921-4C3E-9BEC-C8EE9CC83E01@microsoft.com...
> > Hi Aaron
> >
> > Thank you for the reply. I executed:
> > SELECT ASCII(SUBSTRING(firstname,1,1)),
> > CHAR(ASCII(SUBSTRING(firstname,1,1))) FROM contacthd where  contactnumber
> > =
> > 100000
> >
> >
> > and the ASCII code came as 10.
> >
> > These spaces are causing problems when we mail merge this data and i dont
> > know how easy it is to trim this data in excel. Right now i have to trim
> > several tables and i will then work on triming this in excel. Your
> > response
> > is greatly appreciated
> >
> >
> >
> > "Aaron Bertrand [SQL Server MVP]" wrote:
> >
> >> Can you find out what they are?
> >> E.g.
> >>
> >> SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table
> >>
> >> Also, is the only symptom that you see the box in Enterprise Manager, but
> >> the data works fine in the applications that consume it?  If so, just
> >> stop
> >> looking at the data in Enterprise Manager -- Query Analyzer is a better
> >> place anyway.  And/or, have Excel trim the data BEFORE it sends it to the
> >> database.
> >>
> >>
> >>
> >>
> >>
> >> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> >> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
> >> > Hi All
> >> >
> >> > I have a table that is populated by an excel plugin. Some of the
> >> > populated
> >> > rows have spaces in front. In Enterprise Manager, they appear with
> >> > little
> >> > squares in front.  I have  been trying to LTRIM the whole column but
> >> > there
> >> > is
> >> > no change.
> >> >
> >> > This is what i have been executing for a specifc row with these spaces:
> >> > update Tbcnt
> >> > set firstname = ltrim(firstname)
> >> > where contactnumber = 100000
> >> >
> >> > Is there any special way to trim these spaces. Thank you in advance.
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>
>
Author
2 Mar 2006 10:45 PM
MittyKom
Quick question. Why is it that the ordinary update stmt below did not work?

update Tbcnt
set firstname = ltrim(firstname)
where contactnumber = 100000


Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> UPDATE contacthd
>     SET firstname = SUBSTRING(firstname, 2, LEN(firstname))
>     WHERE ASCII(SUBSTRING(firstname,1,1)) = 10;
>
>
>
> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> news:BC258672-A921-4C3E-9BEC-C8EE9CC83E01@microsoft.com...
> > Hi Aaron
> >
> > Thank you for the reply. I executed:
> > SELECT ASCII(SUBSTRING(firstname,1,1)),
> > CHAR(ASCII(SUBSTRING(firstname,1,1))) FROM contacthd where  contactnumber
> > =
> > 100000
> >
> >
> > and the ASCII code came as 10.
> >
> > These spaces are causing problems when we mail merge this data and i dont
> > know how easy it is to trim this data in excel. Right now i have to trim
> > several tables and i will then work on triming this in excel. Your
> > response
> > is greatly appreciated
> >
> >
> >
> > "Aaron Bertrand [SQL Server MVP]" wrote:
> >
> >> Can you find out what they are?
> >> E.g.
> >>
> >> SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table
> >>
> >> Also, is the only symptom that you see the box in Enterprise Manager, but
> >> the data works fine in the applications that consume it?  If so, just
> >> stop
> >> looking at the data in Enterprise Manager -- Query Analyzer is a better
> >> place anyway.  And/or, have Excel trim the data BEFORE it sends it to the
> >> database.
> >>
> >>
> >>
> >>
> >>
> >> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> >> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
> >> > Hi All
> >> >
> >> > I have a table that is populated by an excel plugin. Some of the
> >> > populated
> >> > rows have spaces in front. In Enterprise Manager, they appear with
> >> > little
> >> > squares in front.  I have  been trying to LTRIM the whole column but
> >> > there
> >> > is
> >> > no change.
> >> >
> >> > This is what i have been executing for a specifc row with these spaces:
> >> > update Tbcnt
> >> > set firstname = ltrim(firstname)
> >> > where contactnumber = 100000
> >> >
> >> > Is there any special way to trim these spaces. Thank you in advance.
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>
>
Author
2 Mar 2006 10:54 PM
Aaron Bertrand [SQL Server MVP]
LTrim in SQL Server, at least, replaces white space.  A line feed character,
again in SQL Server at least, is not white space.





Show quote
"MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
news:15F52079-B3FA-44EF-B2DD-771963FA8141@microsoft.com...
>
> Quick question. Why is it that the ordinary update stmt below did not
> work?
>
> update Tbcnt
> set firstname = ltrim(firstname)
> where contactnumber = 100000
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
>> UPDATE contacthd
>>     SET firstname = SUBSTRING(firstname, 2, LEN(firstname))
>>     WHERE ASCII(SUBSTRING(firstname,1,1)) = 10;
>>
>>
>>
>> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
>> news:BC258672-A921-4C3E-9BEC-C8EE9CC83E01@microsoft.com...
>> > Hi Aaron
>> >
>> > Thank you for the reply. I executed:
>> > SELECT ASCII(SUBSTRING(firstname,1,1)),
>> > CHAR(ASCII(SUBSTRING(firstname,1,1))) FROM contacthd where
>> > contactnumber
>> > =
>> > 100000
>> >
>> >
>> > and the ASCII code came as 10.
>> >
>> > These spaces are causing problems when we mail merge this data and i
>> > dont
>> > know how easy it is to trim this data in excel. Right now i have to
>> > trim
>> > several tables and i will then work on triming this in excel. Your
>> > response
>> > is greatly appreciated
>> >
>> >
>> >
>> > "Aaron Bertrand [SQL Server MVP]" wrote:
>> >
>> >> Can you find out what they are?
>> >> E.g.
>> >>
>> >> SELECT ASCII(SUBSTRING(column_name,1,1)) FROM Table
>> >>
>> >> Also, is the only symptom that you see the box in Enterprise Manager,
>> >> but
>> >> the data works fine in the applications that consume it?  If so, just
>> >> stop
>> >> looking at the data in Enterprise Manager -- Query Analyzer is a
>> >> better
>> >> place anyway.  And/or, have Excel trim the data BEFORE it sends it to
>> >> the
>> >> database.
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
>> >> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
>> >> > Hi All
>> >> >
>> >> > I have a table that is populated by an excel plugin. Some of the
>> >> > populated
>> >> > rows have spaces in front. In Enterprise Manager, they appear with
>> >> > little
>> >> > squares in front.  I have  been trying to LTRIM the whole column but
>> >> > there
>> >> > is
>> >> > no change.
>> >> >
>> >> > This is what i have been executing for a specifc row with these
>> >> > spaces:
>> >> > update Tbcnt
>> >> > set firstname = ltrim(firstname)
>> >> > where contactnumber = 100000
>> >> >
>> >> > Is there any special way to trim these spaces. Thank you in advance.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>
Author
2 Mar 2006 10:55 PM
Roy Harvey
>Quick question. Why is it that the ordinary update stmt below did not work?
>
>update Tbcnt
>set firstname = ltrim(firstname)
>where contactnumber = 100000

LTRIM removes leading blanks.  CHAR(10) is not a blank, it is a
linefeed character.

Roy Harvey
Beacon Falls, CT
Author
2 Mar 2006 11:01 PM
MittyKom
Aaron and Roy, thank you so much.


Show quote
"Roy Harvey" wrote:

> >Quick question. Why is it that the ordinary update stmt below did not work?
> >
> >update Tbcnt
> >set firstname = ltrim(firstname)
> >where contactnumber = 100000
>
> LTRIM removes leading blanks.  CHAR(10) is not a blank, it is a
> linefeed character.
>
> Roy Harvey
> Beacon Falls, CT
>
Author
3 Mar 2006 2:13 PM
Raymond D'Anjou
Show quote
"MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
> Hi All
>
> I have a table that is populated by an excel plugin. Some of the populated
> rows have spaces in front. In Enterprise Manager, they appear with little
> squares in front.  I have  been trying to LTRIM the whole column but there
> is
> no change.
>
> This is what i have been executing for a specifc row with these spaces:
> update Tbcnt
> set firstname = ltrim(firstname)
> where contactnumber = 100000
>
> Is there any special way to trim these spaces. Thank you in advance.

Hi,
They probably are not spaces but some other character.
Try: ASCII(firstname)
to get the ASCII code of the character.
then:
replace(firstname, char(the value returned by ASCII(firstname)), '')

You can replace the 2 operations with:
replace(firstname, char(ASCII(firstname)), '')

If you have more than 1 character to replace and they have different ASCII
values, you can just run the Replace function again.
Author
3 Mar 2006 2:38 PM
Raymond D'Anjou
Show quote
"Raymond D'Anjou" <rdanjou@canatradeNOSPAM.com> wrote in message
news:ulKBF0sPGHA.1696@TK2MSFTNGP14.phx.gbl...
> "MittyKom" <Mitty***@discussions.microsoft.com> wrote in message
> news:7B46E252-C632-45C3-9C51-D3EC402766BB@microsoft.com...
>> Hi All
>>
>> I have a table that is populated by an excel plugin. Some of the
>> populated
>> rows have spaces in front. In Enterprise Manager, they appear with little
>> squares in front.  I have  been trying to LTRIM the whole column but
>> there is
>> no change.
>>
>> This is what i have been executing for a specifc row with these spaces:
>> update Tbcnt
>> set firstname = ltrim(firstname)
>> where contactnumber = 100000
>>
>> Is there any special way to trim these spaces. Thank you in advance.
>
> Hi,
> They probably are not spaces but some other character.
> Try: ASCII(firstname)
> to get the ASCII code of the character.
> then:
> replace(firstname, char(the value returned by ASCII(firstname)), '')
>
> You can replace the 2 operations with:
> replace(firstname, char(ASCII(firstname)), '')
>
> If you have more than 1 character to replace and they have different ASCII
> values, you can just run the Replace function again.

Forget the second solution I gave.
You really need to identify the ASCII code of the offending character(s).
select ASCII(firstname) from Tbcnt where contactnumber = 100000

For example, lets say the character is a Tab (ASCII 9).
Then do:
update Tbcnt set firstname = replace(firstname, char(9), '')
Author
3 Mar 2006 2:47 PM
Aaron Bertrand [SQL Server MVP]
> replace(firstname, char(the value returned by ASCII(firstname)), '')

Well, with firstname, this probably works.  But for something like address,
that might have valid cr/lf pairs embedded within, probably safer to just
replace the first one...
Author
3 Mar 2006 2:57 PM
Raymond D'Anjou
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:u1Q6gDtPGHA.2052@TK2MSFTNGP10.phx.gbl...
>> replace(firstname, char(the value returned by ASCII(firstname)), '')
>
> Well, with firstname, this probably works.  But for something like
> address, that might have valid cr/lf pairs embedded within, probably safer
> to just replace the first one...

Yeah I know. :-(
I should have my first coffee before answering any posts.
At least the poster has an idea now on how to identify the character(s).

AddThis Social Bookmark Button