locked
Prefixed with 0 for a number RRS feed

  • Question

  • Hi All,

    I need to change the default for the customer.ref_no column to be prefixed by 00000 so that if the field is blank or less than 5 long it will be left filled with 0s.

    What is the syntax for that?

    sth like this will work?

    ref_no = Right('00000'+Substring(customer.ref_no,1,5),5)

     

    Please advise.

     

    Cheers 

    CC


    This person has no signature.
    • Edited by Royal Oak Monday, April 19, 2010 10:34 PM
    Monday, April 19, 2010 10:30 PM

Answers

  • Select right('00000' + cast(myIntField as varchar(5)),5) as PrefixedField
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Proposed as answer by ShawnNWF Monday, April 19, 2010 11:26 PM
    • Marked as answer by Royal Oak Monday, April 19, 2010 11:49 PM
    Monday, April 19, 2010 10:33 PM