Selecting data from SQL Server table according to Month

Posted by MarceloRamires on Stack Overflow See other posts from Stack Overflow or by MarceloRamires
Published on 2010-03-31T20:12:27Z Indexed on 2010/03/31 20:13 UTC
Read the original article Hit count: 417

Filed under:
|
|
|
|

I have to come up with a way to get data from a SQL server table given it's month

There's a smalldatetime type field called "date" in the "events" table and a field from it looks like this:

29/01/2003 17:00:00

It should be one among those that appear in the gridview when I select jan/03 in a given DropDownList control in ASP.NET.

What would be the best way to do this? Assuming I only want to go as long as 10 years to the past, wouldn't making a dictionary be a good way? How do I change it so the top month is always the current, and each month another options appeaars in the dropdown ?

It should be a common issue, so that shall not be a trick, but I want a good and clean way of doing this, and (since I'm new to asp.net) I myself would come up with something messy after a long time trying.

So what I want is:
-Select -Best way of populating DropDownList (with the current month always at the top)
-Best way to bind the DropDownList user-friendly way of writing months to the select query-friendly way of writing datetimes

Info:
ASP.NET, (C# or VB.NET), SQL Server 2005

© Stack Overflow or respective owner

Related posts about sql

Related posts about query