Author |
Topic |
kellog1
Starting Member
35 Posts |
Posted - 2010-06-29 : 15:13:59
|
Gurus,I would like get rid of leading zeroes from Varchar column...Here is what the data looks like currently..Col1006TH ST005TH STDesired Result:Col1 6th ST5th STThanks in advance. |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-06-29 : 15:38:13
|
This is the easy wayselect replace(Col1 ,'00','')but this may be safer for your dataselect replace(Col1,'00','') from yourTablewhere Col1 like '[0][0]%'JimEveryday I learn something that somebody else already knew |
 |
|
X002548
Not Just a Number
15586 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-29 : 17:17:29
|
[code]DECLARE @Sample TABLE ( Data VARCHAR(20) NOT NULL )INSERT @SampleVALUES ('006TH ST'), ('005TH ST')SELECT Data, SUBSTRING(Data, PATINDEX('%[^0]%', Data), LEN(Data)) AS PesoFROM @Sample[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-30 : 10:48:24
|
Yes. Sorry for that. And thank you for fixing the sample data! N 56°04'39.26"E 12°55'05.63" |
 |
|
X002548
Not Just a Number
15586 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-07-01 : 02:27:24
|
quote: Originally posted by Peso
DECLARE @Sample TABLE ( Data VARCHAR(20) NOT NULL )INSERT @SampleVALUES ('006TH ST'), ('005TH ST')SELECT Data, SUBSTRING(Data, PATINDEX('%[^0]%', Data), LEN(Data)) AS PesoFROM @Sample N 56°04'39.26"E 12°55'05.63"
Seems you are fully working on 2008 only MadhivananFailing to plan is Planning to fail |
 |
|
|