title: Equivalent of GETDATE() BETWEEN Two DateTime Fields where Both can be NULL
body: <p>Is</p>
  
  <pre><code>SELECT [Id]
        ,[DateOnline] --Nullable
        ,[DateOffline] --Nullable
        ,[PageId]
        ,[DownloadId]
        ,[Weight]
    FROM [DownloadPage]
    WHERE GETDATE() BETWEEN [DateOnline] AND [DateOffline]
  </code></pre>
  
  <p>Equivalent to:</p>
  
  <pre><code>SELECT [Id]
        ,[DateOnline] --Nullable
        ,[DateOffline] --Nullable
        ,[PageId]
        ,[DownloadId]
        ,[Weight]
    FROM [DownloadPage]
    WHERE ([DateOnline] IS NULL OR [DateOnline] &lt;= GETDATE())
    AND ([DateOffline] IS NULL OR [DateOffline] &gt; GETDATE()) 
  </code></pre>
  
  <p>But with also catering for NULLs?</p>
  
  <p>Or is there a more elegant way of doing it?</p>
  
  <p>Where are parentheses needed here?</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:</p>
  
  <p><strong>Both [DateOnline] AND [DateOffline] are of type DateTime</strong></p>
  
  <p><strong>If [DateOnline] is NULL then the logic is "online now"</strong></p>
  
  <p><strong>If [DateOffline] is NULL then the logic is "never go offline (once online)"</strong></p>
  
  <p>Sorry, I should have included this in my question to begin with.</p>