UPDATE: I rewrote the first part as a setbased approach:
declare @AllRunnersString nvarchar(200) ='2342;1228;1075;266;423;2849;1690;488;162;1153;1666'
DECLARE @pairs table
(p1 int,p2 int)
insert into @pairs(p1, p2)
select sp1.value as p1, sp2.value as p2
from dbo.split(';', @AllRunnersString) sp1
inner join dbo.split(';', @AllRunnersString) sp2
on sp1.value <> sp2.value
This generates the pairs.
Head2Head takes the ids and returns a table with all events with both ids. @rtn table( eventid int, p1 int, p2 int, ldiff float, pdiff float, winner int )
I need to take all of these events and store them in a table for all of the combinations from @pairs.
Using a procedure based approach, I would run a cursor over the @pairs, and using a procedure calculate the values for each pair and insert into the final table.
Maybe there is a setbased approach to this part..