Vaishali Gupta
Vaishali Gupta

Reputation: 1

How to auto increment alphanumeric column by 1

I have a column stating with value 't0005453'. How can I update this column till 't0005803'.

Should I put an auto increment in the column. I tried this with update query to just increment this by 1. But that is throwing null value.

Upvotes: 0

Views: 163

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269503

If you like, you can add a computed column to mimic what you want:

create table t (
    t_id int identity(1, 1) primary key,
    . . . ,
    my_id as ('t' as format(t_id, '0000000'))
);

Then the value is calculated on-the-fly based on the primary key column.

Upvotes: 1

Related Questions