Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In one of my tables I have a varchar column namely 'cityarea_name'. In some of the rows, this column data starts with a blank space (one character). I dont know how it happenned.
Can anyone suggest me an exact sql query for rectifying this 'cityarea_name' column. I want to remove this starting blank space only for those rows where actually it has happenned.

Updated 1-May-13 4:58am

1 solution

You could simply perform an update on all the records like this:
SET cityarea_name = LTRIM(cityarea_name)
There's no reason to narrow down the scope of the update because you will probably slow down the update if you try to do something like this:
SET cityarea_name = LTRIM(cityarea_name)
WHERE LEFT(cityarea_name, 1) = ' '
Share this answer
S.Rajendran from Coimbatore 1-May-13 11:47am    
I tried with both the above. It is not getting trimmed.
Pete O'Hanlon 1-May-13 17:37pm    
If it's not getting trimmed, then it's not a space character.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900