Pad A String With Leading Zeros for Specified Value Range in SQL Server -


i've used answer @ pad string leading zeros it's 3 characters long in sql server 2008

to pad column leading zeros in case it's 2 zeros , i'm using this:

right('0'+isnull(replace(<columnname>, '"', ''),''),2) 

data ranges 1 99 includes value of of 'unk' unknown truncated using method.

is there way around or should exploring different solution i'm dealing text , numbers in same column?

cheers

j

(second revision) try this:

select case when len(isnull(<columnname>, '')) > 1   isnull(<columnname>, '')   else right ('00'+ isnull(<columnname>, ''), 2) end 

sample input/output:

input null  / ouput '00' input 'unk' / ouput 'unk' input '1'   / ouput '01' input '99'  / ouput '99' 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -