Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
evanburen
Posting Yak Master
167 Posts |
Posted - 2011-01-10 : 10:09:25
|
I have some values in an int column which when imported from another data source is dropping the leading zero. Every value should contain 16 digits. For example, 770070040800000 should be 0770070040800000. so far I've used If LEN(columnname) = 15 to identify the bad values but I don't know how to udpate them to include the leading zero.Thanks |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-01-10 : 10:17:10
|
SELECT REPLICATE('0',16 - len(columname) + columnnameJimEveryday I learn something that somebody else already knew |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-10 : 11:11:57
|
please keep in mind that converting to varchar would make integer manipulations difficult.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-01-10 : 12:28:16
|
quote: Originally posted by evanburen I have some values in an int column which when imported from another data source is dropping the leading zero. Every value should contain 16 digits. For example, 770070040800000 should be 0770070040800000. so far I've used
Int values do not have leading zeros. So, you can either1. Change the data type to a non-numeric type (like varchar) (bad idea)2. Add a computed column.3. Keep the int column and just convert it to a string when you select out or let the front end handle/convert it. |
 |
|
|
|
|