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?
Don’t pass DateTime as a string. Use SQL Command and pass it as
DateTime.Now.Tear()Short Code Example:
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.