hizakemi, you should post which method you took into consideration as you said all methods worked well. I take MVJ's code as an exampleselect SAPcode as Actual_Code, MVJ=right('000000'+SAPCode,6), Tara = CASE WHEN DATALENGTH(SAPCode) < 6 THEN '0' + SAPCode ELSE SAPCode END ,Srinika=REPLICATE('0', 6 - DATALENGTH(CAST(SAPCode as VARCHAR(6)))) + convert(varchar(6), SAPCode) from(select SAPCode = '' union allselect SAPCode = '2' union allselect SAPCode = '22' union allselect SAPCode = '222' union allselect SAPCode = '2222' union allselect SAPCode = '22222' union allselect SAPCode = '222222333') a where len(SAPCode)<6MadhivananFailing to plan is Planning to fail