Click here to Skip to main content
11,714,776 members (78,101 online)
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 3:57am
Edited 1-May-13 3: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 Sergey Alexandrovich Kryukov 570
1 Richard MacCutchan 275
2 Maciej Los 274
3 OriginalGriff 140
4 CHill60 135
0 Sergey Alexandrovich Kryukov 545
1 CHill60 375
2 Maciej Los 324
3 Richard MacCutchan 310
4 OriginalGriff 260


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
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