House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Order by question

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

Order by question

Oh, and my solution is for MS SQL 2000 ... Jenny Gavin-Wear 04/11/2008 08:03 PM
Hi Paul, Jenny Gavin-Wear 04/11/2008 07:59 PM
You can make the field a text data type Bobby Hartsfield 04/03/2008 09:50 PM
its ms sql 2k Paul Ihrig 04/03/2008 06:11 PM
Also, if you're using SQL Server (or MySQL) this one's even easier: Andy Matthews 04/03/2008 06:01 PM
I'm retarded...this is the query you want for MySQL: Andy Matthews 04/03/2008 05:58 PM
the closest I could get was Greg Morphis 04/03/2008 05:56 PM
Paul... Andy Matthews 04/03/2008 05:50 PM
Paul Ihrig wrote: Ian Skinner 04/03/2008 05:47 PM
Opps too many quotes on the Listsort function.... Gerald Guido 04/03/2008 05:47 PM
You can turn the result set into a list and then do a list sort and sort it Gerald Guido 04/03/2008 05:46 PM
Gerald Paul Ihrig 04/03/2008 05:31 PM
Kris. Paul Ihrig 04/03/2008 05:29 PM
Are you storing the numbers as text or as a number in the database? If you Gerald Guido 04/03/2008 05:21 PM
it is not sorting this way... Paul Ihrig 04/03/2008 05:16 PM
Try this out. You need to sort by a text value of the hier_num Kris Jones 04/03/2008 05:03 PM
If I understand right, he wants the alpha order, not the numeric order. To morgan l 04/03/2008 05:03 PM
Paul Ihrig wrote: Ian Skinner 04/03/2008 04:56 PM
if i have a bunch of numbers that i want to order like this in a drop Paul Ihrig 04/03/2008 04:38 PM

04/11/2008 08:03 PM
Author: Jenny Gavin-Wear Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#303222 Oh, and my solution is for MS SQL 2000 ... Hi Paul, You can make use of CONVERT (or CAST, I think). For example: The table to be sorted here has two columns, the ID and the values to be sorted: SELECT     TOP 100 PERCENT tempID, CONVERT(varchar, NumValues) AS TextValues FROM         dbo.tbl_temp ORDER BY CONVERT(varchar, NumValues) In your code it would be: <cfquery name="get_PH" datasource="xxx"> SELECT convert(varchar, hier_num) as TextValues, .hier_desc FROM hierarchy ORDER BY CONVERT(varchar, hier_num) </cfquery> Hope this helps, Jenny if i have a bunch of numbers that i want to order like this in a drop dowm, how do i do it? the origional order by id was fine when the list was small.. but now it has grown. forcing it to look the way we want below is boggeling.. 1 101 101010 2 201 202 201010 201020 3 302 et....... <cfquery name="get_PH" datasource="xxx"> SELECT hier_num, .hier_desc FROM hierarchy </cfquery> if i order by hier_num it just does as expected 1 2 3 101 201 301 et.... as always i appreciate your help.
04/11/2008 07:59 PM
Author: Jenny Gavin-Wear Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#303221 Hi Paul, You can make use of CONVERT (or CAST, I think). For example: The table to be sorted here has two columns, the ID and the values to be sorted: SELECT     TOP 100 PERCENT tempID, CONVERT(varchar, NumValues) AS TextValues FROM         dbo.tbl_temp ORDER BY CONVERT(varchar, NumValues) In your code it would be: <cfquery name="get_PH" datasource="xxx"> SELECT convert(varchar, hier_num) as TextValues, .hier_desc FROM hierarchy ORDER BY CONVERT(varchar, hier_num) </cfquery> Hope this helps, Jenny if i have a bunch of numbers that i want to order like this in a drop dowm, how do i do it? the origional order by id was fine when the list was small.. but now it has grown. forcing it to look the way we want below is boggeling.. 1 101 101010 2 201 202 201010 201020 3 302 et....... <cfquery name="get_PH" datasource="xxx"> SELECT hier_num, .hier_desc FROM hierarchy </cfquery> if i order by hier_num it just does as expected 1 2 3 101 201 301 et.... as always i appreciate your help.
04/03/2008 09:50 PM
Author: Bobby Hartsfield Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302686 You can make the field a text data type -or- create another column that is identical and gets updated and everything else just like the other column but make it text and order by that instead
04/03/2008 06:11 PM
Author: Paul Ihrig Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302674 its ms sql 2k but alas. it is game/beer time. so i will look at it again in the morning thanks every one for being so helpful On Thu, Apr 3, 2008 at 6:00 PM, Andy Matthews <lists@commadelimited.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 06:01 PM
Author: Andy Matthews Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302673 Also, if you're using SQL Server (or MySQL) this one's even easier: SELECT * FROM tmp ORDER BY ascii( c ) ASC Paul... What DBMS are you using? In MySQL 5, sorting a numeric column apparently defaults to sorting alphabetically. CREATE TABLE `tmp` (   `c` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO tmp (c) VALUES (1); INSERT INTO tmp (c) VALUES (101); INSERT INTO tmp (c) VALUES (101010); INSERT INTO tmp (c) VALUES (2); INSERT INTO tmp (c) VALUES (201); INSERT INTO tmp (c) VALUES (201010); INSERT INTO tmp (c) VALUES (201020); SELECT * FROM `tmp` ORDER BY c ASC Gerald they are nums in a num field they sort correctly if i wanted them sorted like a number. but powers that be want them sorted in a was to show hierarchy.. nm... i will tell them we can recreat the table with the order they want by hand...
04/03/2008 05:58 PM
Author: Andy Matthews Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302672 I'm retarded...this is the query you want for MySQL: SELECT CONCAT( '0' + c ) AS value FROM tmp ORDER BY value The previous wasn't sorted alpha by default...I'm just an idiot. The above query though does return your desired result set: 1 101 101010 2 201 201010 201020 Paul... What DBMS are you using? In MySQL 5, sorting a numeric column apparently defaults to sorting alphabetically. CREATE TABLE `tmp` (   `c` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO tmp (c) VALUES (1); INSERT INTO tmp (c) VALUES (101); INSERT INTO tmp (c) VALUES (101010); INSERT INTO tmp (c) VALUES (2); INSERT INTO tmp (c) VALUES (201); INSERT INTO tmp (c) VALUES (201010); INSERT INTO tmp (c) VALUES (201020); SELECT * FROM `tmp` ORDER BY c ASC Gerald they are nums in a num field they sort correctly if i wanted them sorted like a number. but powers that be want them sorted in a was to show hierarchy.. nm... i will tell them we can recreat the table with the order they want by hand...
04/03/2008 05:56 PM
Author: Greg Morphis Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302671 the closest I could get was select * from foo order by rpad(col, 10, '0') But it does not the results you're asking. On Thu, Apr 3, 2008 at 4:49 PM, Andy Matthews <lists@commadelimited.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:50 PM
Author: Andy Matthews Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302670 Paul... What DBMS are you using? In MySQL 5, sorting a numeric column apparently defaults to sorting alphabetically. CREATE TABLE `tmp` (   `c` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO tmp (c) VALUES (1); INSERT INTO tmp (c) VALUES (101); INSERT INTO tmp (c) VALUES (101010); INSERT INTO tmp (c) VALUES (2); INSERT INTO tmp (c) VALUES (201); INSERT INTO tmp (c) VALUES (201010); INSERT INTO tmp (c) VALUES (201020); SELECT * FROM `tmp` ORDER BY c ASC Gerald they are nums in a num field they sort correctly if i wanted them sorted like a number. but powers that be want them sorted in a was to show hierarchy.. nm... i will tell them we can recreat the table with the order they want by hand...
04/03/2008 05:47 PM
Author: Ian Skinner Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302668 Paul Ihrig wrote: > Gerald > they are nums in a num field > they sort correctly if i wanted them sorted like a number. > but powers that be want them sorted in a was to show hierarchy.. OK then reverse my original advice.  Tell your system to sort them as characters rather then numbers. You should be able to do this with a simple CAST in your ORDER BY clause, if you are not using to simple a database management system.
04/03/2008 05:47 PM
Author: Gerald Guido Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302669 Opps too many quotes on the Listsort function.... ListSort(valuelist(get_PH.hier_num, ","), "TextNoCase", "ASC", ",") On Thu, Apr 3, 2008 at 5:45 PM, Gerald Guido <gerald.guido@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:46 PM
Author: Gerald Guido Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302666 You can turn the result set into a list and then do a list sort and sort it alphabetically like so: ListSort(valuelist(get_PH.hier_num, "",""), "TextNoCase", "ASC", ",") or this (will probably run faster) ListSort(valuelist(get_PH.hier_num, "",""), "Text", "ASC", ",") And then loop over the list for your drop down. G On Thu, Apr 3, 2008 at 5:31 PM, Paul Ihrig <pihrig@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:31 PM
Author: Paul Ihrig Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302665 Gerald they are nums in a num field they sort correctly if i wanted them sorted like a number. but powers that be want them sorted in a was to show hierarchy.. nm... i will tell them we can recreat the table with the order they want by hand...
04/03/2008 05:29 PM
Author: Paul Ihrig Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302664 Kris. thats closer to what i an looking for. but not exact... it now does 1 1100105 1100101 10 1001 100101 100102 1002 100201 100202 1003 100301 100303 101 i would like 1 10 101 1001 100101 100102 1002 100201 100202 1003 100301 100303 1100105 1100101 shjt.. not even sure if this makes sense...
04/03/2008 05:21 PM
Author: Gerald Guido Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302663 Are you storing the numbers as text or as a number in the database? If you are doing an "order by" and the numbers are being stored as text in the database the numbers will be sorted like words and not numbers. On Thu, Apr 3, 2008 at 5:15 PM, Paul Ihrig <pihrig@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:16 PM
Author: Paul Ihrig Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302662 it is not sorting this way... i Want it to sort this way On Thu, Apr 3, 2008 at 4:55 PM, Ian Skinner <HOF@ilsweb.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:03 PM
Author: Kris Jones Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302659 Try this out. You need to sort by a text value of the hier_num select hier_num, hier_desc, convert(varchar(20),hier_num) hier_text from hiertbl order by hier_text Cheers, Kris On Thu, Apr 3, 2008 at 4:37 PM, Paul Ihrig <pihrig@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 05:03 PM
Author: morgan l Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302660 If I understand right, he wants the alpha order, not the numeric order. To that end, I have no suggestions, db & sql stuff are not my strong skills. On Thu, Apr 3, 2008 at 3:55 PM, Ian Skinner <HOF@ilsweb.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
04/03/2008 04:56 PM
Author: Ian Skinner Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302658 Paul Ihrig wrote: ----- Excess quoted text cut - see Original Post for more ----- This is an alphabetical order of numbers.  Why the list is being order alphabetically I can not say without seeing some relevant code.  But the solution is to tell your code to treat this data a numerical data not character data.
04/03/2008 04:38 PM
Author: Paul Ihrig Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55879#302657 if i have a bunch of numbers that i want to order like this in a drop dowm, how do i do it? the origional order by id was fine when the list was small.. but now it has grown. forcing it to look the way we want below is boggeling.. 1 101 101010 2 201 202 201010 201020 3 302 et....... <cfquery name="get_PH" datasource="xxx"> SELECT hier_num, .hier_desc FROM hierarchy </cfquery> if i order by hier_num it just does as expected 1 2 3 101 201 301 et.... as always i appreciate your help.
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference