0

I would like to know how I can convert the following Oracle SQL code into SQL Server:

TO_CHAR(NUM_COL, '00000')

is

CAST(('00000'+ NUM_COL) AS VARCHAR(MAX))

correct?

Expected Output: if NUM_COL = 1 => 00001 if NUM_COL = 24 => 00024 if NUM_COL = 383 => 00383

Platus
  • 1,753
  • 8
  • 25
  • 51
  • what exactly are you trying to achieve? use of `TO_CHAR('STH', '00000')` is incorrect. You want to spell a number, or it's something else you are after? – Nick Krasnov Jun 14 '17 at 07:49
  • @NicholasKrasnov please check my last edit, NUM_COL is a numeric field, so it prefixes it with zeroes – Platus Jun 14 '17 at 07:55

1 Answers1

1

If your requirement is to preceed value with 0 then I guess following solves your requirement:(PS=> 5 because I wanted result in exact 5 values, if you want different than change tha value)

   SELECT RIGHT('00000'+convert(varchar,NUM_COL),5)
Ranjana Ghimire
  • 1,785
  • 1
  • 12
  • 20