DECLARE @MAX_sno int=null; SELECT @MAX_sno=MAX(person_id) FROM TABLENAME WHERE companycode='Your_companycode' ; SET @MAX_sno=@MAX_sno+1; ----In MAX_sno you will get new sno value which can be used for new record insertion
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)