Create the function first, to store the function in the database.create function NextCustomerNumber() returns varchar(6) as begin declare @lastval varchar(6) set @lastval = (select max(empid) from employee) if @lastval is null set @lastval = 'EM0001' declare @i int set @i = right(@lastval,4) + 1 return 'EM' + right('000' + convert(varchar(10),@i),4) end
AND NOW YOU create the stored procedure.CREATE Procedure addcustomer(@EMPName nvarchar(255),@PASSWORD nvarchar(25),@EMAILID nvarchar(50),@DESIGNATION nvarchar(50), )ASINSERT INTO EMPLOYEE(empid,empname,passwords,emailid, designation)select NextCustomerNumber(), @EMPName,@PASSWORD,@EMAILID,@DESIGNATION
E 12°55'05.25"N 56°04'39.16"