Search code examples
sqlsql-server-2008formulapersisted-column

How can you format a persisted column as a padded integer string [SQL Server 2008]


What formula would I use in a persisted column so that I can add the two columns below together, the first must be padded to 5 characters:

  • ID (INT)
  • RefNum (STRING)

I went for format(ID,"00000") & RefNum, but it doesn't work, any ideas please?


Solution

  • SELECT RIGHT('00000' + CAST(ID AS VARCHAR(5)), 5) + RefNum