SQL Statement errorhttp://forums.asp.net/t/1799167.aspx/1?SQL+Statement+errorFri, 04 May 2012 07:49:40 -040017991674961409http://forums.asp.net/p/1799167/4961409.aspx/1?SQL+Statement+errorSQL Statement error <p>Hi,&nbsp;</p> <p>I have a gridview that displays the result of a table, and I have &nbsp;<strong>2 DropDownList</strong> and <strong>2 BasicDatePicker</strong>: <strong>(The SQL statement work fine but when loading the page I get an SQL depassement Time )</strong></p> <p>When I try to use:</p> <pre class="prettyprint">SELECT * FROM Missions WHERE ( (@Division = 'NULL' OR Division = @Division) AND (@Lieu = 'NULL' OR Lieu = @Lieu) AND (@Date1 IS NULL OR Date1&gt;= @Date1) AND (@Date2 IS NULL OR Date2 &lt;= @Date2) )</pre> <p><br> <br> </p> <p>I get an SQL dépassement time, even If set the default value to something not null</p> <p></p> <p>Any help plz?</p> <p><br> <br> </p> 2012-05-02T09:49:41-04:004961420http://forums.asp.net/p/1799167/4961420.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p>What types are Division etc?&nbsp; Why are you using =&quot;null&quot; sometimes and IS NULL others?&nbsp; IS NULL is the correct way.&nbsp; What does &quot;SQL dépassement time&quot; mean?</p> 2012-05-02T09:52:49-04:004961467http://forums.asp.net/p/1799167/4961467.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p></p> <blockquote><span class="icon-blockquote"></span> <h4>AidyF</h4> What types are Division etc?&nbsp; Why are you using =&quot;null&quot; sometimes and IS NULL others?&nbsp; IS NULL is the correct way.&nbsp; What does &quot;SQL dépassement time&quot; mean?</blockquote> <p></p> <p>Division: string</p> <p>Lieu: string</p> <p>Date1: Datetime</p> <p>Date2: Datetime</p> <p></p> <p>SQL Dépassement time: means that the time is less than 1/1/1750 or more than 31/12/9999</p> 2012-05-02T10:09:55-04:004961613http://forums.asp.net/p/1799167/4961613.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p>HI</p> <p>Try change to:</p> <pre class="prettyprint">SELECT * FROM Missions WHERE ( (@Division IS NULL OR ( @Division IS NOT NULL AND Division = @Division)) AND (@Lieu IS NULL OR (@Lieu IS NOT NULL AND Lieu = @Lieu)) AND (@Date1 IS NULL OR (@Date1 IS NOT NULL AND Date1&gt;= @Date1)) AND (@Date2 IS NULL OR (@Date2 IS NOT NULL AND Date2 &lt;= @Date2)) )</pre> <pre class="prettyprint"><span class="pun">Case you pass the value 'NULL' in your variables @Division and @Lieu <span>disconsider my changes.</span></span></pre> <pre class="prettyprint"><span class="pun"><span>I hope this help.</span></span></pre> 2012-05-02T11:01:15-04:004961634http://forums.asp.net/p/1799167/4961634.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p>This is the problem :</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>pierrefrc</h4> <p></p> <pre class="prettyprint">(@Date1 IS NULL OR (@Date1 IS NOT NULL AND <strong>Date1&gt;=</strong> @Date1<strong>)</strong>) AND (@Date2 IS NULL OR (@Date2 IS NOT NULL AND <strong>Date2 &lt;=</strong> @Date2<strong>)</strong>) )</pre> <p></p> </blockquote> <p></p> <p>Because when the page load, the datepicker doesn't choose any value</p> <p></p> <p>For division or lieu, I just pass the default value to 'NULL' and it works,&nbsp;</p> <p>For DateTime I can't pass the default value to 'NULL' because it's not a string, so I used the &quot; IS NULL&quot;: It's working on Test but not working when loading the page</p> 2012-05-02T11:07:42-04:004961641http://forums.asp.net/p/1799167/4961641.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p>Do you can to post your code to execute this sql ?</p> 2012-05-02T11:09:50-04:004965080http://forums.asp.net/p/1799167/4965080.aspx/1?Re+SQL+Statement+errorRe: SQL Statement error <p>Hi,</p> <p>In the datepick control in GridView when you bind the field to the property of control. You can make a checking in markup, something like. I suppose it is selecteddate property:</p> <p>selecteddate='&lt;%#&nbsp;(Eval(&quot;fieldname&quot;) == DBNull.Value) ?&nbsp;&quot;***&quot; : Eval(&quot;fieldname&quot;)&nbsp;%&gt;'</p> <p>Thanks,</p> 2012-05-04T07:49:40-04:00