Increment row values with some pre-defined values.

Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 335
create table dummy
[id] [int] identity(1,1) not null,
[idwithchar] as ('p'+right('000'+convert([varchar](15),[id],0),(8))) persisted,
[name] [nvarchar](25) not null,
primary key clustered
[id] asc
)with (pad_index = off,statistics_norecompute = off,ignore_dup_key = off,allow_row_locks = on, allow_page_locks = on) on [primary]
) on [primary]

Note:- [idwithchar] will be treated as our Computed Column.

insert into dummy values('vishal'),('neeraj kumar')
select * from dummy;

1 P0001 Vishal
2 P0002 Neeraj kumar

Comments or Responses

Login to post response