Hi,
I have rewritten an UDF from inline to multi-valued UDF and was able to reduce the query time from ~20seconds down to ~2seconds. All the literature indicates that inline are generally faster than multi valued UDF's.
The original inline query looked something like the following:
create function udf_inline
(
@p1 int,
@p2 datetime
)
returns table
as
return
select
*
from
(
select
*
from
(
select
*
from
tableA
where
col1 = @p1
and col2 = @p2
)
)
I have rewritten the query to use multi lined UDF
CREATE FUNCTION dbo.MV_UDF
(
@p1 INT,
@p2 DATETIME
)
RETURNS @myTable TABLE
(
colA varchar(50),
colB varchar(50),
etc...
)
AS
BEGIN
insert into @myTable
select
*
from
(
select
*
from
(
select
*
from
tableA
where
col1 = @p1
and col2 = @p2
)
)
RETURN
Why the multi-valued UDF runs faster I do not know. Anyone can provide some insight?
thanks