You are here

public function SelectQuery_sqlsrv::orderRandom in Drupal driver for SQL Server and SQL Azure 7.3

Same name and namespace in other branches
  1. 7 sqlsrv/select.inc \SelectQuery_sqlsrv::orderRandom()
  2. 7.2 sqlsrv/select.inc \SelectQuery_sqlsrv::orderRandom()

Override of SelectQuery::orderRandom() for SQL Server.

It seems that sorting by RAND() doesn't actually work, this is a less then elegant workaround.

@status tested

Overrides SelectQuery::orderRandom

File

sqlsrv/select.inc, line 484

Class

SelectQuery_sqlsrv

Code

public function orderRandom() {
  $alias = $this
    ->addExpression('NEWID()', 'random_field');
  $this
    ->orderBy($alias);
  return $this;
}