![]() | ![]() | ![]() |
| |||||||
| Forums | Register | Groups | Awards | Arcade | Pets | T-Bucks / T-Store | Invite Your Friends | Blogs | Mark Forums Read |
| Web Design Forums and discussions on webdesign |
Web Design | |||||||||
|
|
|
|
| |||||
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Civilians | Hi folks, I have a database full of documents and each section within a document is given an ID like "1.0", "1.1", "1.2" and so on. The datatype is varchar (I wasn't sure if a better type exists?). Now this is fine until I get to "1.10" which is then logically between "1.1" and "1.2" but obviously, in the document it should be after "1.9". Is there any way I can retrieve data from the database using this sort of /logical to me, but not to a computer/ manner? Just in case I am making no sense (which is quite likely); at the moment I am using something like: "SELECT id FROM sections ORDER BY id ASC" Which returns: 1.1, 1.10, 1.11, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 Whereas I would like to get it in the order: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10. 1.11 Is there something magical I can use to achieve this? Cheers, -- Dylan Parry http://webpageworkshop.co.uk -- FREE Web tutorials and references |
|
| | #2 (permalink) |
| Civilians | Carved in mystic runes upon the very living rock, the last words of Dylan Parry of alt.www.webmaster make plain: > I have a database full of documents and each section within a document > is given an ID like "1.0", "1.1", "1.2" and so on. The datatype is > varchar (I wasn't sure if a better type exists?). > > Now this is fine until I get to "1.10" which is then logically between > "1.1" and "1.2" but obviously, in the document it should be after > "1.9". Is there any way I can retrieve data from the database using > this sort of /logical to me, but not to a computer/ manner? If SQL Server has the CAST() function and the DECIMAL type, you could try that: order by cast(id as DECIMAL); -- Alan Little Phorm PHP Form Processor http://www.phorm.com/ |
|
| | #3 (permalink) |
| Civilians | And lo, Dylan Parry didst speak in alt.www.webmaster: > Just in case I am making no sense (which is quite likely); at the moment > I am using something like: > > "SELECT id FROM sections ORDER BY id ASC" > > Which returns: > > 1.1, 1.10, 1.11, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 > > Whereas I would like to get it in the order: > > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10. 1.11 > > Is there something magical I can use to achieve this? Would this work? "SELECT id FROM sections ORDER BY LENGTH(id) ASC, id ASC" Grey -- The technical axiom that nothing is impossible sinisterly implies the pitfall corollory that nothing is ridiculous. - http://www.greywyvern.com/orca#ring - Orca Ringmaker: Host a webring from your website! |
|
| | #4 (permalink) |
| Civilians | Create a function that parses the string into two halves. Pre-decimal half, and post decimal half. Here's some pseudo code; sLeft=left(sInput,at('.',sInput) sRight=substr(sInput,at('.',sInput)+1 iValue=StrToInt(sLeft)*100+StrToInt(sRight) return iValue On Fri, 14 Oct 2005 15:20:30 +0100, Dylan Parry wrote: > Hi folks, > > I have a database full of documents and each section within a document is > given an ID like "1.0", "1.1", "1.2" and so on. The datatype is varchar (I > wasn't sure if a better type exists?). > > Now this is fine until I get to "1.10" which is then logically between > "1.1" and "1.2" but obviously, in the document it should be after "1.9". > Is there any way I can retrieve data from the database using this sort of > /logical to me, but not to a computer/ manner? > > Just in case I am making no sense (which is quite likely); at the moment I > am using something like: > > "SELECT id FROM sections ORDER BY id ASC" > > Which returns: > > 1.1, 1.10, 1.11, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 > > Whereas I would like to get it in the order: > > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10. 1.11 > > Is there something magical I can use to achieve this? > > Cheers, -- George Sexton MH Software, Inc. - Home of Connect Daily Web Calendar http://www.mhsoftware.com/conectdaily.htm |
|
| | #5 (permalink) |
| Civilians | "Dylan Parry" <usenet@dylanparry.com> wrote in message news:nucbaci7fn1r$.dlg@dylanparry.com... > Hi folks, > > I have a database full of documents and each section within a document > is given an ID like "1.0", "1.1", "1.2" and so on. The datatype is > varchar (I wasn't sure if a better type exists?). > > Now this is fine until I get to "1.10" which is then logically between > "1.1" and "1.2" but obviously, in the document it should be after "1.9". > Is there any way I can retrieve data from the database using this sort > of /logical to me, but not to a computer/ manner? > > Just in case I am making no sense (which is quite likely); at the moment > I am using something like: > > "SELECT id FROM sections ORDER BY id ASC" > > Which returns: > > 1.1, 1.10, 1.11, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 > > Whereas I would like to get it in the order: > > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10. 1.11 > > Is there something magical I can use to achieve this? > > Cheers, > > -- > Dylan Parry I would add three numeric fields and store numeric values there as parts of the entire ID For example ID1 = 1 ID2 = 1 ID3 = 2 would give us 1.1.2 Select query will look like select * from sections order by ID1,ID2,ID3 ![]() Vlad http://wowdealz.com |
|
| | #6 (permalink) |
| Civilians | On Sat, 15 Oct 2005 00:26:15 +0100, Dylan Parry <usenet@dylanparry.com> wrote: >If only changing the database was an option! It is. Make a scratch table with the separated section numbering and put a foreign key from it into the "data" table. |
|
![]() |
| Bookmarks |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SQL Server Login Error while connecting from MPP to Project Server.Please help | Sreejith | Microsoft Applications | 2 | 12-30-2006 06:34 |
| Possible to install Project 2003 Server on W2K3 Server DC?? | screwie | Microsoft Applications | 1 | 11-18-2004 14:35 |
| NAS Storage Server 2003 & Server 2000 | =?Utf-8?B?R3JhZW1lIFdhbGtlcg==?= | Microsoft Applications | 1 | 07-30-2004 08:02 |
| SQL Server / Analysis Server as source for powerpoint charts | Richm | Microsoft Applications | 2 | 06-16-2004 11:17 |
| sort a column of numbers including minus numbers | Rasoul Khoshravan Azar | Microsoft Applications | 7 | 06-15-2004 23:45 |
![]() | ![]() | ![]() |