I'm working in SQL Server 2012. I'm cleaning data, and am trying to break ties in an address-assigning algorithm randomly. This requires me to generate random numbers. The approach taken by this answer doesn't work because the WITH subquery seems to regenerate each side of the join, resulting in different random numbers for the same row.
This code replicates the problem:
WITH
initial_table AS (
SELECT 1 AS id
),
random_values_added AS (
SELECT id, ABS(CHECKSUM(NEWID())) % 10 AS rand
FROM initial_table
)
SELECT t1.id, t2,id, t1.rand, t2.rand
FROM random_values_added t1 FULL OUTER JOIN random_values_added t2
ON t1.id = t2.id AND t1.rand = t2.rand