Saturday, February 25, 2012

RTrim and LTrim with UPDATE

You all have been so much help, but I've discovered yet another problem. I'm trying to clean up my table using the following command:
UPDATE dbo.TableName
SET First_Name = LTrim(RTrim(First_Name))But it does not seem to have any effect. Thoughts? Thanks!Should work fine. It's possible that your string has characters that appear as spaces, but which are actually a different ASCII value.|||Thr LTrim function works fine when I use it in conjunction with SELECT, just not UPDATE.|||Thr LTrim function works fine when I use it in conjunction with SELECT, just not UPDATE.

Is it possible you are dealing with a char (and not a varchar) column?

Regards,

hmscott|||Yes, that's correct. Is that wrong?|||Char is fixed length, so your data will be padded.
Better to use varchar in this situation.
In fact, char should only be used when the length is fixed and is under about 10 characters.
These days, zip codes are one of the few elements I store as char.|||Thanks, I originally switched from NVARCHAR, so I will update the tables..

No comments:

Post a Comment