Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:39:49+00:00 2026-05-29T05:39:49+00:00

We have a web application written with asp.net/c# and uses sql server as SGBD

  • 0

We have a web application written with asp.net/c# and uses sql server as SGBD in our database, in almost tables, we have a column called ‘YEAR’, so in a lot of select statement we have

select * from table where ... and  Year = '2012' 

for example

is there any way to refactor those queries in order to make the ‘and Year = ‘2012” part implicit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:39:50+00:00Added an answer on May 29, 2026 at 5:39 am

    Don’t pass DateTime as a string. Use SQL Command and pass it as
    DateTime.Now.Tear()

    Short Code Example:

    void int SQLQueryWith Implicit Date() { 
        // Create a sql statement with a parameter (@ImplicitYear) 
        string sql = @"SELECT rank = Count(*) 
                       FROM   table 
                       WHERE  table.date >= @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(); 
        }  
    

    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.

    Edit based on updated info,

    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.

    Additional Idea:
    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 ( http://blogs.msdn.com/b/sqlcat/archive/2007/06/06/querying-a-database-snapshot.aspx) and you wouldn’t need to include the years as long as you know the snapshots.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net web application written in C# using a SQL Server 2008
I have in here an old web application written in ASP.Net 2.0 + AJAX.
I have started upgrading one of our internal software applications, written in ASP.NET Web
I currently have a web application written by ASP.NET MVC. Now I want to
I have a forum like web application written in Asp.net MVC. I'm trying to
We have a ASP.NET web application written in VB.NET where we build content programmatically
I have a web application written in C#/ASP.Net and the backend DB is Oracle.
I have a web-application written on ASP.NET MVC 3. On client side I used
This is odd, but we have written an asp.Net web application (all's well there)
We have a web application written in ASP.NET for .NET 3.5, using standard web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.