Alternative way of Fetching the Next Value in Sql Server.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 276
create table Project_Master
(
project_id int identity not null primary key,
project_name varchar(100)
)

create function Next_Project_Number(@id int)
returns char(5)
as
begin
return 'P' + right('0000' + convert(varchar(10),@id),4);
end


Using above function,we can simply add a computed column to our table like below:-
alter table Project_Master 
add Next_Project_Number as dbo.Next_Project_Number(project_id);

Comments or Responses

Login to post response