Here is my code
Create function [dbo].[CASNo]()
returns varchar(20) as
begin
DECLARE @lastval INT
SET @lastval = (select MAX(Cast(right(CAS_No,4) as varchar(10))) from tblCASdetails)
if @lastval is null set @lastval = 0
Return 'CAS-' + right('000' + convert(varchar(50),(@lastval + 1)),10)
end

Bryian TanRank #396 · 6.3K reputationPosted Sep 10, 2018, 6:10 PM EDT
Methoun Ahmed148 reputationPosted Sep 13, 2018, 10:00 AM EDT
Jayesh VaghasiyaRank #9,790 · 202 reputationPosted Sep 17, 2018, 3:40 AM EDT