Create function NextCustomerNumber
(
@TABLE_NAME varchar(20)
)
returns varchar(10)
as
begin
declare @lastval varchar(10)
set @lastval = right('000000000' + convert(varchar(10),(select IsNull(max(Serialno),0)+1 from TestSerialNo)),10)
return @lastval
end
please tell me how could i return serial no to its calling environment make the sql dynamic inside function not store procedure.
Stored Procedureif you need to useDynamic SQLNo dynamic SQL inside functions?identitycolumn and either create the string representation when selecting the data or create a computed column that does that for you (which can also be a persisted computed column). For more information, read this SO post