3

Algorithmically speaking, how could I generate a unique, human readable, reasonably lengthed - order number for SQL Server column. The only requirement is that it references the Customer Number and can be easily repeated over the phone.

Something like:

  • Customer Number - XXXXXXXX - XXXXXXXX

RT65-XXXXXXXX-XXXXXXXX

How would I generate the XXXXXXXX? (Use random alpha-numeric data and then checking to see if it was in fact a duplicate?)

and

What are the best methods/considerations when generating these types of numbers?

How have you done this in your application?

  • Can it be a hash or does the order number have to correlate with the customer? I know when I do my banking, my confirmation number follows a convention: numerical month, numerical day, time in hours, time in minutes. As an example, it would be 1271259 – Anthony Forloney Jan 27 '10 at 17:59

4 Answers4

2

Use an identity column and pad with zeros.

Alter the start and increment values to taste.

Optionally, add a CRC check digit.

wefwfwefwe
  • 3,382
  • 1
  • 21
  • 24
  • 2
    For a check digit, I've always been a fan of making the number a multiple of 11. The most common data entry error is digit reversal, followed by wrong digit. Both of those errors always change the value of a number mod 11. – phkahler Jan 27 '10 at 18:11
1

Check out these posts, nearly the exact same question. Real good data in both (I've used them before):

A good algorithm for generating an order number

What is the best format for a customer number, order number?

Community
  • 1
  • 1
dpb
  • 1,205
  • 2
  • 9
  • 20
0

This is silly but fairly straight forward, How about yyyymmddhhmmss

and use it with

RT65-XXXXXXXX-XXXXXXXX

Vivek Bernard
  • 2,063
  • 3
  • 26
  • 43
0

in php you can do like the following:

<?php 
$stamp = strtotime("now");
$orderid = 'RT65-'.$stamp.'-'.$REMOTE_ADDR; 
$orderid = str_replace(".", "", $orderid); 
echo($orderid); 
?>
Mirodil
  • 2,321
  • 2
  • 30
  • 38