-1

Need to add "00" in-front of each row and the size of col1 is 3 i.e., (varchar(3))

I have data as below

col1
-----
1
02
003
4
05

I need to update the col1 values like prefix(001, 002, 003, 004, 005) as shown below.

col1
-----
001
002
003
004
005

I tried with SQL Server replicate function but I didn't get.

Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
venugopal
  • 79
  • 10
  • 2
    Probably duplicate of [Pad a string with leading zeros so it's 3 characters long in SQL Server 2008](https://stackoverflow.com/questions/16760900/pad-a-string-with-leading-zeros-so-its-3-characters-long-in-sql-server-2008) – GoGoris Jan 23 '19 at 12:15

1 Answers1

1

This is really a presentation layer requirement. I recommend just storing your col1 values an integers, and then generating the zero padded number using something like:

SELECT RIGHT('000' + CAST(col1 AS VARCHAR(3)), 3) AS col1_out
FROM yourTable;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360