I am trying to speed up my monster of a stored procedure that works on millions of records across many tables.
I've stumbled on this: Is it possible to use a Stored Procedure as a subquery in SQL Server 2008?
My question is why using a table valued function be better then using a temp table.
Suppose my stored procedure @SP1
declare @temp table(a int)
insert into @temp
select a from BigTable
where someRecords like 'blue%'
update AnotherBigTable
set someRecords = 'were blue'
from AnotherBigTable t
inner join
@temp
on t.RecordID = @temp.a
After reading the above link it seems that the consunsus is instead of using my @temp as temp table, rather create a table valued function that will do that select. (and inline it if its a simple select like I have in this example) But my actual selects are multiple and often not simple (ie with subqueires, etc) What is the benefit?
Thanks