T-SQL field formatting

18 March 2007 21:41 (EST)
Here is a tip on number formatting with T-SQL.

For example, you have a numeric field called ProductNumber and want to have it as six-char string with leading zeros.

SELECT RIGHT(REPLICATE('0',5)+CONVERT(VARCHAR,ProductNumber),6) FROM Products