July 14, 2013 at 9:26 am
How can I convert the below function to return table. I am thinking of putting in cross apply rather than calling scalar function as this is getting expensive call.
CREATE function [dbo].[myfunc]
returns money
Begin
declare d as money
set d = -(select isnull(sum(d.cola),0)
from (Select distinct c.cola
from tab1 b
join tab2 c
on b.cola = c.colb
where b.cola <= @b-2 and
b.colb = @a) c
join tab3 d
on c.cola = d.colb and
@a <> d.cola)+@c
return d
End
July 14, 2013 at 1:09 pm
Without more information, I would say you could do it like this.
CREATE function [dbo].[myfunc]
returns table
AS
return
select d = (isnull(sum(d.cola),0)+@c) * -1
from (Select distinct c.cola
from tab1 b
join tab2 c
on b.cola = c.colb
where b.cola <= @b-2 and
b.colb = @a) c
join tab3 d
on c.cola = d.colb and
@a <> d.cola
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply