Wednesday, March 21, 2012

Order By

Is there a way to order data how you want besides Ascending or Descending? Example: I have M-F I need to sort in order of Monday-Friday.

Hi,

you could split up the queries to execute one for Monday, Tuesday... Friday. Then you can process the result sets in the order you want.

Otherwise I would store ordinals in the database like Monday = 0, Tuesday = 1 and so on.

--
SvenC

|||I don't quite understand could you send me a breif example?|||

Hi,

instead of using one SqlCommand with an order by clause you could set up one SqlCommand which selects only rows where Day = Monday, a second SqlCommand which selects Day = Tuesday and so on. So you end up with one DataSet or DataTable per day.

Otherwise you would have to modify the table to change how your day is represented. Change it from varchar to int, and store 0 instead of 'Monday' and 1 instead of 'Tuesday', so the numbers sort like you want the days to sort.

Does that help you?

--
SvenC

|||Yeah thats a good Idea I do have it store as 1's and 0's, and am combining as with case command as the day value. Thanks

No comments:

Post a Comment