2

I don't know if this is possible in SQL Server but I'm gotta ask it ;-)

I have a column called duty in a table work.

So say Work.Duty contains different numbers, like so (1, 2, 3, 20, 22, 305, 306, etc...)

A duty number should always be 3 digits long, but they are imported from a flat file and they are supplied as is.

Is it possible to add 1 or 2 zero's in a statement so all duty numbers have 3 digits (001, 002, 020, 021, 305, 306)?

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Davevmb
  • 85
  • 1
  • 11

2 Answers2

3

Assuming that yourColumn is Varchar(...), try:

SELECT FORMAT(CAST(yourColumn AS INT),'000','en-US') from yourTable;
NoChance
  • 5,393
  • 2
  • 29
  • 37
3

Try this:

SELECT RIGHT(1000 + Duty, 3) AS newDuty
FROM Work
Kaf
  • 32,033
  • 7
  • 53
  • 77