To use a Scalar function or Table valued function,in sql server to determine the best -
i using sql-server 2012
my table definition is:
create table products1(pid int,pnm varchar(10),oid int foreign key references orders1(oid)) create table orders1(oid int primary key,onm varchar(10),odt date) insert products1 values(1,'abc',1),(2,'def',2) insert orders1 values(1,'qty','2013-04-27'),(2,'prod','2015-04-29') create function dbo.udf_getmaxdt(@a date) returns date begin select @a=max(o.odt) orders1 o inner join products1 p on o.oid=p.pid return @a end create function dbo.udf_getmaxdt(@a date) returns table return ( select @a=max(o.odt) orders1 o inner join products1 p on o.oid=p.pid ) end
the syntax might wrong on task determine best of 2 types of function.
but aint able tell one,could me on this?
regards, chio
the first 1 scalar function
the second 1 inline table valued udf
the second 1 has pattern can recognize:
create function [dbo].[fn_geo_calcdistance] ( ... ) returns table return select ...
the second 1 , when inlined query , cause query not referenced outside query inline query , mush faster
Comments
Post a Comment