Fetching the Next Value.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 220
create function Fetching_Next_Project_Number() 
returns char(5)
as
begin
declare @lastval char(5);
set @lastval = (select max(project_id) from Project_Master)
if @lastval is null
set @lastval = 'P0001';

declare @i int;
set @i = right(@lastval,4) + 1;
return 'P' + right('000' + convert(varchar(10),@i),4)
end

Comments or Responses

Login to post response