RAND()
viene eseguito solo una volta per query.
Puoi verificarlo guardando il set di risultati.
Se stai cercando di ottenere un ordine casuale, dovresti utilizzare NEWID()
o CHECKSUM(NEWID())
.
WITH T AS ( -- example using RAND()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, RAND()
FROM T;
WITH T AS ( -- example using just NEWID()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, NEWID()
FROM T;
WITH T AS ( -- example getting the CHECKSUM() of NEWID()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, CHECKSUM(NEWID())
FROM T;