I use the sp_LPAD stored procedure wherever I need to generate a padded string, like a bank account or serial number. It's a bit like the Oracle built-in function of the same name, and can be called like this:
EXEC sp_LPAD @OrderRef OUTPUT
Obviously, you'll need to CAST or CONVERT the parameter if it is a numeric. By default the string will be padded with zeroes, although a second (optional) parameter can be specified which contains the pad character to use.
Author: James Page
Disclaimer: We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
"as -is", without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose...
Back to Database Journal Home