title: ISNULL not working in TSQL Select
body: <p>I have a TSQL SELECT that can return a null.  I tried using ISNULL to replace it with 0 but for some reason it is not working.  The table selecting from has the following columns:</p>
  
  <ul>
  <li>storeID --> int </li>
  <li>penaltyPercent --> decimal(9,2) </li>
  <li>penaltyDate --> dateTime</li>
  </ul>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT  ISNULL(penaltyPercent, 0.0) AS penaltyPercent  
  FROM    dbo.Penalty  
  WHERE   (penaltyDate = (SELECT     MAX(penaltyDate) AS date  
                          FROM       dbo.Penalty AS Penalty_1  
                          WHERE      (penaltyDate &lt;= @date) AND (storeID = @storeID))) AND
          (storeID = @storeID) 
  </code></pre>
  
  <p>When the date is before the first penalty date (when there should be 0 penalty), no result is returned.  Not sure why this doesn't work.  I have a work around but it is bugging me.</p>
  
  <p>Here is a sample of the data being used:</p>
  
  <pre><code>storeID  penaltyDate             penaltyPercent  
  182      10/1/2008 12:00:00 AM   0.020000  
  182      11/1/2008 12:00:00 AM   0.040000  
  182      12/1/2008 12:00:00 AM   0.070000  
  </code></pre>