Forum Discussion

BenjaminChew's avatar
BenjaminChew
Copper Contributor
Aug 19, 2025

adding computed column to MS SQL

would like to check how to add a computed column with the following requirement

Column value will be C-yyyyMMdd-0001

where date will be from the CreatedDate column in the same table. 

0001 is an auto-incremental value based on when the record is inserted on the same day

eg, the first record added on 23/08/2025, the computed column will be C-20250823-0001.

 

As the table may already contain existing data, a SQL script may also be necessary to update this new column with the correct value.

3 Replies

  • rodgerkong's avatar
    rodgerkong
    Iron Contributor

    Should this column be inserted with other columns in one SQL command? Or the column can be filled with a trigger? Or the insert script can be writen in a Stored Procedure?

      • rodgerkong's avatar
        rodgerkong
        Iron Contributor

        Could you add a small table in your db to record the max number, or add the table by your dba?

Resources