Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have a few problems.</p> <p>First, is in your <code>CASE</code> statements, you are using syntax for <code>substring</code> similar to this:</p> <pre><code>substring(convert(varchar(10), cast(II.DueDate$DATE as datetime), 104) from 7 for 1) ='-') </code></pre> <p>The <a href="http://msdn.microsoft.com/en-us/library/ms187748.aspx" rel="nofollow"><code>substring()</code></a> syntax is:</p> <pre><code>SUBSTRING ( expression ,start , length ) </code></pre> <p>You will notice that there is no <code>from</code> used. So your code would be something like:</p> <pre><code>substring(convert(varchar(10), cast(II.[DueDate$DATE] as datetime), 104), 7, 1) ='-' </code></pre> <p>Second, you are using pipes <code>||</code> to concatenate data together in SQL Server you will want to use a plus sign <code>+</code>. So replace:</p> <pre><code>...5)||'0'||substring... </code></pre> <p>With:</p> <pre><code>...5)+'0'+substring... </code></pre> <p>Third, replace the <code>current_date</code> with <code>getdate()</code>. Another thing you will have to fix when you replace the <code>current_date</code> with <code>getdate()</code> is the following:</p> <pre><code>cast(getdate() as varchar(10)) </code></pre> <p>This will return a value of the current date in a format that you will not want to use. I recommend looking at the following website to determine the best format for your comparison:</p> <p><a href="http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/" rel="nofollow">How to format datetime &amp; date in Sql Server 2005</a></p> <p>Typically, you would want to use something like:</p> <pre><code>convert(varchar(8), getdate(), 112) – yyyymmdd </code></pre> <p>Last, any columns that have a special character in them <code>DueDate$DATE</code> need to be wrapped in square brackets. So they will look like:</p> <pre><code>...cast(II.[DueDate$DATE]... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload