Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a varchar field field. Some of the values of data in the field are 5,6, and 8 digit numbers, some are not.Is there a SQL statement I can use to change only the 5 and 6 digit numbers to 8 digit numbers by adding 0s to the front of them?Example:12345 would become 00012345and 123456 would become 00123456.I also realize I might have to do this in 2 statements, and that would be fine as well. The tricky part of it is that there is also some data that is not numbers at all that I want to leave alone.
spejbl
Starting Member
28 Posts
Posted - 2007-03-08 : 12:24:20
this trick is your friend:
CASE WHEN ISNUMERIC(YourColumn)=1 THEN RIGHT('00000000' + YourColumn, 8) ELSE YourColumnEND