Question : xp_executesql in function

intro:
i try to write a function for generating new PK values

function:
CREATE function dbo.sysNewId (@tabName nvarchar(4000))
returns int
AS
begin
declare @text nvarchar (4000), @newId int
set @text='select @newId= isnull( min( id), 0 )+1 from '+ @tabName+ ' where id+1 not in ( select id from '+ @tabName+ ')'
execute master.dbo.sp_executesql @text, N'@newId int out', @newId out
return (@newId)
end

query:
    select dbo.sysNewId ( 'sysclass')

error
Server: Msg 557, Level 16, State 2, Procedure ssysNewId, Line 11
Only functions and extended stored procedures can be executed from within a function.

question:
  What is the meaning of error, if  sp_executesql is extended stored procedure?

Answer : xp_executesql in function

sp_executesql is a system stored procedure, NOT a extended stored procedure...
Random Solutions  
 
programming4us programming4us