block user by sql query
If not Views Bulk Operations as mentioned in the comment above by arpitr there seems to be one function from the core users module which appears to be of the purpose for the same. The User module's hook_user_operations for block operation namely user_user_operations_block would be it to answer your query and should provide you a drupal code way of doing it. 

function user_user_operations_block($accounts) {
  foreach ($accounts as $uid) {
    $account = user_load(array('uid' =&gt; (int) $uid));
    // Skip blocking user if they are already blocked.
    if ($account !== FALSE &amp;&amp; $account-&gt;status == 1) {
      user_save($account, array('status' =&gt; 0));
    }
  }
}


Essentially it loads the user account and makes call to user_save with the status as 0. If your implementation is to block users with custom code based on a specific logic, you could do the same or perhaps consider invoking the user module's hook_user_operations for block operation with the desired input though I haven't done something similar. Doing so would prevent you writing your own update query. Hope that helps.