Try this:
--Create a temp table with some random points for testing purposes
create table #Points(
idint identity(1,1) not null,
x decimal(10,5),
y decimal(10,5))
declare @count int = 0
while @count < 20
begin
insert into #Points(x,y)
values (rand()*100.0 -...