Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2008R2
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.
 
Thanks.
Posted 1-May-13 4:57am
Edited 1-May-13 4:58am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could simply perform an update on all the records like this:
UPDATE MyTable
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:
UPDATE MyTable
SET cityarea_name = LTRIM(cityarea_name)
WHERE LEFT(cityarea_name, 1) = ' '
  Permalink  
Comments
S.Rajendran from Coimbatore at 1-May-13 11:47am
   
I tried with both the above. It is not getting trimmed.
Pete O'Hanlon at 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)

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100