as
begin
declare
@id nvarchar(12);
-- if customerID exists means get max value and increment that value
-- else add First value
if (select count(*) from CustomerDetails )>0
begin;
select @id=max(right(I D,5)) from CustomerDetails
set @id=right(@id,5 )
set @id=cast(@id as float)+1
set @id='CU'+Right( '00000' + Convert(varchar (5), @id), 5)
end;
else
set @id='CU00001'
Comment