Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't pass DateTime as a string. Use SQL Command and pass it as <code>DateTime.Now.Tear()</code></p> <p>Short Code Example: </p> <pre><code>void int SQLQueryWith Implicit Date() { // Create a sql statement with a parameter (@ImplicitYear) string sql = @"SELECT rank = Count(*) FROM table WHERE table.date &gt;= @ImplicitYear"; // Create a sql connection // Always use the using statement for this using (var connection = new SqlConnection(connectionString)) { // Create a sql command // Always use the using statement for this using (var command = new SqlCommand(sql, connection)) { // Pass the dateinput argument to the command, and let // the .NET Framework handle the conversion properly! command.Parameters.Add(new SqlCommand("ImplicitYear", DateTime.Now.Year())); // No need for calling .Close() or .Dispose() - the using // statements handle that for us return (int)command.ExecuteScalar(); } </code></pre> <p>Or if you have a stored procedure on the database side, you could make it implicit within the stored procedures and just pass the paramaters that you need.</p> <p><strong>Edit based on updated info,</strong></p> <p>You could create temp tables on the database side with one query dividing each into separate years. You could do this against all the tables with one query and then drop the year from the rest of your queries if you point to the right tables.</p> <p><strong>Additional Idea:</strong> I'm not too fluent with how this works but based on a little research, you could create filtered database snapshots for each year and update them on a daily basis on the server side. (msdn.microsoft.com/en-us/library/ms175876.aspx) Then run queries against the snapshots ( <a href="http://blogs.msdn.com/b/sqlcat/archive/2007/06/06/querying-a-database-snapshot.aspx" rel="nofollow">http://blogs.msdn.com/b/sqlcat/archive/2007/06/06/querying-a-database-snapshot.aspx</a>) and you wouldn't need to include the years as long as you know the snapshots.</p>
 

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