trying to create a view that shows leading zero's

  • Hello *,

    I am to write a view which must show leading

    zero's. I do have the oracle equivalent, just can't get the mss variant in order . Can

    anyone please help?

    create view ZEROOS_V1

    ( field1 )

    as select

    LPAD (LTRIM (field1, 7, '0') ,

    from the_entity

  • create view zeroos_v1

    as

    select right(replicate('0',7)+field1,7)

    from the_entity

    go

  • Or

    SELECT replicate('0',7-LEN(field1)) + CAST(field1 AS VARCHAR(7)) as field1 from the_entity

    but you will need to cast field1 to a varchar to make sure concatination does not come up a numeric value and thus dropping 0's.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply