You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is with the RAND() function. RAND() on an MSSQL backend will always return the same value for each row in the result set. As such, ordering the rows by the return value of RAND() and selecting the top n rows will just return the data in its initial order:
An alternative approach to generating random numbers on an MSSQL backend is given here. It works by using NEWID() to return a globally unique identifer for each row, hashing the GUID with CHECKSUM() and using this as a seed for RAND():
Using
slice_sample()
on an MSSQL backend always return the same rows:Created on 2024-05-16 with reprex v2.1.0
The issue is with the
RAND()
function.RAND()
on an MSSQL backend will always return the same value for each row in the result set. As such, ordering the rows by the return value ofRAND()
and selecting the topn
rows will just return the data in its initial order:Created on 2024-05-16 with reprex v2.1.0
An alternative approach to generating random numbers on an MSSQL backend is given here. It works by using
NEWID()
to return a globally unique identifer for each row, hashing the GUID withCHECKSUM()
and using this as a seed forRAND()
:Created on 2024-05-16 with reprex v2.1.0
Changing the
runif()
function translation in the MSSQL backend should be straightforward:The text was updated successfully, but these errors were encountered: