3 ms·
For SQL Server it looks like an index seek on the following so it is evaluated once. SELECT * FROM SomeTable WHERE ID = CAST(Rand() * 1000 as int) In addition
by jcriddle4 8y ago
For SQL Server it looks like an index seek on the following so it is evaluated once.
SELECT *
FROM SomeTable
WHERE ID = CAST(Rand() * 1000 as int)
In addition this query: SELECT TOP(100) rand() AS RandData from SomeTable
Returns:
0.940284064056996
0.940284064056996
0.940284064056996
. . . .
A old trick to actually get random data on SQL Server that I think has been replaced with newer functionality is:
SELECT ABS(CHECKSUM(NEWID()))
FROM SomeTable
However if we move the NEWID.... stuff into the WHERE clause we end up switching to an index seek so back to being evaluated once.