title: How to avoid false positive on SQL query checking for IS NULL?
body: <p>How to avoid false positive on SQL query checking for IS NULL?</p>
  
  <p>I seemed to have corrected my false positives by adding the <code>if(sqlsrv_has_rows</code> statement. </p>
  
  <p>PHP:</p>
  
  <pre><code>/*
  
  IF select of 1900 datein has rows
  update datein
  
  IF select of 1900 dateout has rows
  update dateout
  
  IF select of 1900 datein AND dateout no rows
  insert datein
  
  */
  $datein_s="SELECT TOP 1 datein FROM clocked WHERE datein='1900-01-01 00:00:00' AND userid=? ORDER BY datein DESC";
  $datein_sr=sqlsrv_query($dbconnect,$datein_s,$params) or die("Error datein:".print_r(sqlsrv_errors(),true));
  $datein=sqlsrv_fetch($datein_sr);
  if(sqlsrv_has_rows($datein_sr)===FALSE)
  {
  $datein="NOROWS";
  }
  else
  {
  $datein="HASROWS";
  }
  
  $dateout_s="SELECT TOP 1 dateout FROM clocked WHERE dateout='1900-01-01 00:00:00' AND userid=? ORDER BY dateout DESC";
  $dateout_sr=sqlsrv_query($dbconnect,$dateout_s,$params) or die("Error dateout:".print_r(sqlsrv_errors(),true));
  $dateout=sqlsrv_fetch($dateout_sr);
  echo $dateout;
  if(sqlsrv_has_rows($dateout_sr)===FALSE)
  {
  $dateout="NOROWS";
  }
  else
  {
  $dateout="HASROWS";
  }
  
  if($datein==="HASROWS")
  {
  $datein_q1="UPDATE clocked SET datein=GETDATE() WHERE EXISTS(SELECT TOP 1 datein FROM clocked WHERE datein='1900-01-01 00:00:00' AND userid=? ORDER BY datein DESC);";
  $datein_qr1=sqlsrv_query($dbconnect,$datein_q1,$params) or die("Error update datein:".print_r(sqlsrv_errors(),true));
  echo "Datein and out are HASROWS";
  }
  else if ($dateout==="HASROWS")
  {
  $dateout_q1="UPDATE clocked SET dateout=GETDATE() WHERE EXISTS(SELECT TOP 1 dateout FROM clocked WHERE dateout='1900-01-01 00:00:00' AND userid=? ORDER BY dateout DESC);";
  $dateout_qr1=sqlsrv_query($dbconnect,$dateout_q1,$params) or die("Error update dateout:".print_r(sqlsrv_errors(),true));
  echo "Dateout NOROWS";
  }
  else if ($datein==="NOROWS"&amp;&amp;$dateout==="NOROWS")
  {
  $datein_q2="INSERT INTO clocked(datein,userid) VALUES(GETDATE(),?);";
  $datein_qr2=sqlsrv_query($dbconnect,$datein_q2,$params) or die("Error insert datein:".print_r(sqlsrv_errors(),true));
  echo "Datein and Dateout NOROWS";
  }
  else
  {
  echo "ERROR your query may be broken!";
  }
  </code></pre>