Wednesday, March 21, 2012

Is it possible to create a function from within a stored procedure?

I would like to create an UDF from withing a stored procedure. Is it possible?
Thanks a lot.Originally posted by EMoscosoCam
I would like to create an UDF from withing a stored procedure. Is it possible?

Thanks a lot.
try something like this:

declare @.S varchar(1000)

select @.S='
CREATE FUNCTION dbo.fn_test
(
@.p1 int,
@.P2 int
)
RETURNS int
AS
BEGIN
DECLARE @.sum AS int
SELECT @.sum = @.p1 + @.P2
RETURN @.sum
END'
exec(@.S)
go
select dbo.fn_test(5,2)|||Thank you very much! it worked just fine.

No comments:

Post a Comment