Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / September 2005

Tip: Looking for answers? Try searching our database.

I need Urgent help please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dimitris - 29 Sep 2005 08:53 GMT
In a table I have a column with numbers from 1-1000. I need to sort them by
odds and evens. For example 1,3,5,7,9,11.....999 and after 999 the next
number should be 2,4,6,8,10....1000. Is it possible? and how?
Thanks
Dimitris
Baz - 29 Sep 2005 09:11 GMT
> In a table I have a column with numbers from 1-1000. I need to sort them by
> odds and evens. For example 1,3,5,7,9,11.....999 and after 999 the next
> number should be 2,4,6,8,10....1000. Is it possible? and how?
> Thanks
> Dimitris

SELECT * FROM some_table ORDER BY some_column Mod 2 DESC, some_column
Dimitris - 29 Sep 2005 09:28 GMT
Thanks Baz.
You saved my day!

>> In a table I have a column with numbers from 1-1000. I need to sort them
> by
[quoted text clipped - 4 lines]
>
> SELECT * FROM some_table ORDER BY some_column Mod 2 DESC, some_column
Keith - 29 Sep 2005 10:06 GMT
>> In a table I have a column with numbers from 1-1000. I need to sort them
> by
[quoted text clipped - 4 lines]
>
> SELECT * FROM some_table ORDER BY some_column Mod 2 DESC, some_column

Hi Baz,

Could you explain how that works for the benefit of my small brain?

Thanks.
Keith.
Baz - 29 Sep 2005 10:58 GMT
> >> In a table I have a column with numbers from 1-1000. I need to sort them
> > by
[quoted text clipped - 11 lines]
> Thanks.
> Keith.

The Mod (modulus) operator performs a division, but it returns the remainder
instead of the result.  So:

1 Mod 2 = 1
2 Mod 2 = 0
3 Mod 2 = 1
4 Mod 2 = 0

and so on.

So, "some_column Mod 2" returns 1 when some_column is odd, and returns 0
when some_column is even.

Therefore, a descending sort by "some_column Mod 2" puts all the odd values
of some_column before the even values.

Finally, the ascending sort of some_column puts the values in ascending
order within odd and even.
Keith - 29 Sep 2005 11:36 GMT
> The Mod (modulus) operator performs a division, but it returns the
> remainder
[quoted text clipped - 16 lines]
> Finally, the ascending sort of some_column puts the values in ascending
> order within odd and even.

Thanks Baz, I was not familiar with the Mod operator and couldn't find
anything about it in the help.  That's quite a neat solution.

Regards,
Keith.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.