Click here to Skip to main content
11,920,156 members (57,809 online)
Rate this:
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.

Posted 1-May-13 4:57am
Edited 1-May-13 4:58am

1 solution

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

Solution 1

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) = ' '
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)

  Print Answers RSS
0 OriginalGriff 455
1 phil.o 170
2 CPallini 150
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,153
3 George Jonsson 2,810
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web04 | 2.8.151120.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