Попробуйте это
SELECT A.id,B.id, IIF(B.id<>0,A.Id/B.ID,0) AS ExpectedResult,
COALESCE( A.id/NULLIF(B.ID,0),0) AS ExpectedResult2
FROM
(
SELECT Id,ROW_NUMBER()OVER(Order BY ID) As Seq FROM #test1
)As A
INNER JOIN
(
SELECT Id,ROW_NUMBER()OVER(Order BY ID DESC) As Seq FROM #test2)AS B
ON A.Seq=B.Seq
Результат
id id ExpectedResult ExpectedResult2
10 10 1 1
20 10 2 2
30 0 0 0
40 0 0 0