Results 1 to 2 of 2

Thread: Replicate

  1. #1
    Join Date
    Dec 2002
    Posts
    1

    Replicate

    I need to find the next Id to be used in an order and pad a 0 to the front..

    I know that I can select the max(strIid)+1 and get the next orderid. How do I use the Replicate function to add a leading zero to the id which is a varchar(5)?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can do this

    SELECT REPLICATE('0', 5 - DATALENGTH(cast(StrIid as char(5)))) + ltrim(cast(StrIid as char(5)))
    FROM table

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •