0

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.

  • 2
    You should make it an `int` column and use the normal auto increment function. When you select the value you can format it like you want on-the-fly. No need to store that `T`. – juergen d Oct 17 '19 at 13:16
  • 1
    In short you don't. This comes up every now and then and it doesn't really make any sense. What is t + 1? If you must keep the alpha portion you should move it to another column. Then you have a letter column and a number column. Incrementing the number is painless. – Sean Lange Oct 17 '19 at 13:17
  • pls go through link https://stackoverflow.com/a/4699628/11876883 – Nits Patel Oct 17 '19 at 13:19

1 Answers1

1

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786