statement has a syntax errorhttp://forums.asp.net/t/1726558.aspx/1?statement+has+a+syntax+errorWed, 05 Oct 2011 15:22:48 -040017265584623543http://forums.asp.net/p/1726558/4623543.aspx/1?statement+has+a+syntax+errorstatement has a syntax error <p>Could someone please help me figure out why I have a syntax error. Thanks.</p> <p>(Syntax error (missing operator) in query expression DataSource3.publisher = DataSource1.publisher LEFT OUTER JOIN (SELECT publisher, COUNT(ps_projectmgmt) AS CountProjectMGMT.)</p> <p></p> <pre class="prettyprint">SELECT DataSource1.publisher, IIf(IsNull([CountProjectMGMT]),&quot;na&quot;, Val(DataSource1.SumProjectMGMT/DataSource2.CountProjectMGMT)) AS AvgProjectMGMT, IIf(IsNull([CountDesign]),&quot;na&quot;, Val(DataSource1.SumDesign / DataSource3.CountDesign)) AS AvgDesign FROM (SELECT publisher, SUM(IIf(IsNull([ps_projectmgmt]) OR [ps_projectmgmt]=&quot;na&quot;,0, Val([ps_projectmgmt]))) AS SumProjectMGMT, SUM(IIf(IsNull([ps_projectmgmt]) OR [ps_projectmgmt]=&quot;na&quot;,0, Val([ps_projectmgmt]))) AS SumDesign FROM evaluations GROUP BY publisher) AS DataSource1 LEFT OUTER JOIN (SELECT publisher, COUNT(ps_design) AS CountDesign FROM evaluations AS Table_1_2 WHERE (ps_design &lt;&gt; &quot;na&quot;) GROUP BY publisher) AS DataSource3 ON DataSource3.publisher = DataSource1.publisher LEFT OUTER JOIN (SELECT publisher, COUNT(ps_projectmgmt) AS CountProjectMGMT FROM evaluations AS Table_1_1 WHERE (ps_projectmgmt &lt;&gt; &quot;na&quot;) GROUP BY publisher) AS DataSource2 ON DataSource2.publisher = DataSource1.publisher;</pre> 2011-10-03T13:36:17-04:004623559http://forums.asp.net/p/1726558/4623559.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>Try:</p> <p>SELECT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSource1.publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IIf(IsNull([CountProjectMGMT]),&quot;na&quot;, Val(DataSource1.SumProjectMGMT/DataSource2.CountProjectMGMT)) AS AvgProjectMGMT,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IIf(IsNull([CountDesign]),&quot;na&quot;, Val(DataSource1.SumDesign / DataSource3.CountDesign)) AS AvgDesign&nbsp; <br> FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>(</strong>(SELECT&nbsp;&nbsp; publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(IIf(IsNull([ps_projectmgmt]) OR [ps_projectmgmt]=&quot;na&quot;,0, Val([ps_projectmgmt]))) AS SumProjectMGMT,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(IIf(IsNull([ps_projectmgmt]) OR [ps_projectmgmt]=&quot;na&quot;,0, Val([ps_projectmgmt]))) AS SumDesign<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp;&nbsp; evaluations<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY publisher) AS DataSource1<br> LEFT OUTER JOIN&nbsp; (SELECT&nbsp;&nbsp; publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(ps_design) AS CountDesign <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp;&nbsp; evaluations AS Table_1_2 <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;&nbsp; (ps_design &lt;&gt; &quot;na&quot;) <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY publisher) AS DataSource3<br> ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSource3.publisher = DataSource1.publisher<strong>)</strong><br> LEFT OUTER JOIN (SELECT&nbsp;&nbsp; publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(ps_projectmgmt) AS CountProjectMGMT <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp;&nbsp; evaluations AS Table_1_1 <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;&nbsp; (ps_projectmgmt &lt;&gt; &quot;na&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY publisher) AS DataSource2<br> ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSource2.publisher = DataSource1.publisher;</p> 2011-10-03T13:55:17-04:004625505http://forums.asp.net/p/1726558/4625505.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>Thank you, that removed the syntax error. I have one other question. I am trying to add the following to the SQL statement but it's not working it's giving me a wrong output.</p> <p>WHERE dateSent&gt;=#01/01/2011#</p> <p></p> <p>Any idea where I can add the piece above?</p> <p></p> <p>Thanks</p> 2011-10-04T16:09:56-04:004625794http://forums.asp.net/p/1726558/4625794.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p></p> <blockquote><span class="icon-blockquote"></span> <h4>lm111</h4> <p></p> <p>I am trying to add the following to the SQL statement but it's not working it's giving me a wrong output.</p> <p>WHERE dateSent&gt;=#01/01/2011#</p> <p></p> <p>Any idea where I can add the piece above?</p> <p></p> </blockquote> <p></p> <p>In which table(s) do you want to check the dateSent field?&nbsp;</p> 2011-10-04T21:12:12-04:004626698http://forums.asp.net/p/1726558/4626698.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>The dateSent field is in my evaluations table. Could we check it somehow in the following block of code:</p> <p>(SELECT&nbsp;&nbsp; publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(ps_design) AS CountDesign&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp;&nbsp; evaluations AS Table_1_2&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;&nbsp; (ps_design &lt;&gt; &quot;na&quot;)&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY publisher) AS DataSource3<br> ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSource3.publisher = DataSource1.publisher<strong>)</strong><br> LEFT OUTER JOIN (SELECT&nbsp;&nbsp; publisher,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(ps_projectmgmt) AS CountProjectMGMT&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp;&nbsp; evaluations AS Table_1_1&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;&nbsp; (ps_projectmgmt &lt;&gt; &quot;na&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY publisher</p> <p></p> <p>I tried something like this but the output is not right</p> <p>WHERE (ps_design &lt;&gt; &quot;na&quot; AND dateSent&gt;=#01/01/2011#)&nbsp;</p> <p></p> <p>Thanks</p> 2011-10-05T13:22:49-04:004626718http://forums.asp.net/p/1726558/4626718.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p></p> <blockquote><span class="icon-blockquote"></span> <h4>lm111</h4> <p></p> <p>WHERE (ps_design &lt;&gt; &quot;na&quot; AND dateSent&gt;=#01/01/2011#)&nbsp;</p> <p></p> </blockquote> <p></p> <p>This is&nbsp;correct syntax</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>lm111</h4> <p></p> <p>I tried something like this but the output is not right</p> <p></p> </blockquote> <p></p> <p>The only way to solve this is that you try to explain in words which result you want. Show also some records and the result you want</p> 2011-10-05T13:38:12-04:004626727http://forums.asp.net/p/1726558/4626727.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>Hello,</p> <p></p> <p>Here is the link to my other thread that explains it better.</p> <p><a href="../../../../t/1723766.aspx/1?Display&#43;correct&#43;data&#43;in&#43;GridView">http://forums.asp.net/t/1723766.aspx/1?Display&#43;correct&#43;data&#43;in&#43;GridView</a></p> <p><a href="../../../../t/1723766.aspx/1?Display&#43;correct&#43;data&#43;in&#43;GridView"></a></p> <p>The answer from 'mezzanine74' works fine I just need to figure out how to add the dateSent field.</p> <p></p> <p>Thank you so much.</p> 2011-10-05T13:44:55-04:004626757http://forums.asp.net/p/1726558/4626757.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>I really don't understand what result you want. But to help you a little bit further:</p> <p>When a field can contain either a numeric value, NULL of &quot;na&quot;, You can use the following IIF function to change NULL and &quot;na&quot; in 0, so you can calculate with it:</p> <p>IIF(IsNumeric([ps_projectmgmt]), [ps_projectmgmt], 0)</p> 2011-10-05T13:54:05-04:004626877http://forums.asp.net/p/1726558/4626877.aspx/1?Re+statement+has+a+syntax+errorRe: statement has a syntax error <p>Thanks Hans, it's really difficult to explain the problem I am having. For some reason when I add the dateSent field some output for&nbsp;AvgProjectMGMT and AvgDesign are weird numbers like 170 and 19. But it should be the average like 5 or 4.5 or ...) When I remove the dateSent field from my query everything works great. I just don;t understand why the dateSent field would mess things up. Could you please take &nbsp;look again? Thanks.</p> <p></p> <pre class="prettyprint">SELECT DataSource1.publisher, IIf(IsNull([CountProjectMGMT]),'n/a', ROUND(Val(DataSource1.SumProjectMGMT/DataSource2.CountProjectMGMT),1)) AS AvgProjectMGMT, IIf(IsNull([CountDesign]),'n/a', ROUND(Val(DataSource1.SumDesign/DataSource3.CountDesign),1)) AS AvgDesign FROM ((SELECT publisher, SUM(IIf(IsNull([ps_projectmgmt]) OR [ps_projectmgmt]='na',0, Val([ps_projectmgmt]))) AS SumProjectMGMT, SUM(IIf(IsNull([ps_design]) OR [ps_design]='na',0, Val([ps_design]))) AS SumDesign FROM evaluations GROUP BY publisher) AS DataSource1 LEFT OUTER JOIN (SELECT publisher, COUNT(ps_design) AS CountDesign FROM evaluations AS Table_1_2 WHERE ((ps_design &lt;&gt; 'na') AND (pub='1') AND (dateSent &gt;= #&quot; &#43; calendarTextBox1.Text &#43; &quot;# AND dateSent &lt;= #&quot; &#43; calendarTextBox2.Text &#43; &quot;#)) GROUP BY publisher) AS DataSource3 ON DataSource3.publisher = DataSource1.publisher) LEFT OUTER JOIN (SELECT publisher, COUNT(ps_projectmgmt) AS CountProjectMGMT FROM evaluations AS Table_1_1 WHERE ((ps_projectmgmt &lt;&gt; 'na') AND (pub='1') AND (dateSent &gt;= #&quot; &#43; calendarTextBox1.Text &#43; &quot;# AND dateSent &lt;= #&quot; &#43; calendarTextBox2.Text &#43; &quot;#)) GROUP BY publisher) AS DataSource2 ON DataSource2.publisher = DataSource1.publisher&quot;;</pre> 2011-10-05T15:22:48-04:00