• Luis Cazares - Friday, December 29, 2017 8:56 AM

    Jack Corbett - Friday, December 29, 2017 8:47 AM

    This is an even simpler option:

    WITH VTE AS
      (
       SELECT
        *
       FROM
        (
          VALUES (3),
            (25.75),
            (12),
            (125.8),
            (1000),
            (1857.5)
        ) V (I)
      )
    SELECT VTE.I, FORMAT(I*10, '0000') AS LeadingZeros FROM VTE;

    I usually avoid FORMAT due to its fame of being slow.

    I was just comparing the two for that very reason....format version is much slower on execution times as I thought it would be. Quite noticeable with a cold cache even with a small set of data. Keep thinking maybe there is some scenario where it is more useful, isn't so slow but haven't found one yet.

    Sue