Wednesday 9 July 2008

Padding Zeroes in SQL

Building a little script in SQL to allow me to autogenerate mobile phone numbers.

I know I can do this with Red-Gate's Data Generator but it is nice to build the SQL yourself.

Anyways the SQL to pad the mobile phone number with zeroes is:

 

-- This ensures my number is 11 digits long 079 + 8 other digits (padded with zeroes at the beginning

'079' + REPLICATE('0', (8 - LEN(@number))) + @number)

No comments: