create function idincr() returns nvarchar(50)
as begin
declare @id int, @cid nvarchar(50), @did int
set @id=(select count(*) from tblcust)
if(@id>0)
begin
set @did= (select max(cast(substring(custid,2,len(custid))as int))from tblcust)+1;
set @cid='A'+cast(@did as nvarchar(50))
end
else
set @cid='A1'
return @cid
end
Go
select dbo.idincr()
Go
No comments:
Post a Comment