Go Back   Trackpads Community > General Discussions > Computer and Technology > Web Design

Web Design Forums and discussions on webdesign

Web Design

Reply
 
LinkBack Thread Tools
Old 10-14-2005, 13:04   #1 (permalink)
Dylan Parry
Civilians

 
Default SQL Server: Getting numbers in (right) order

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
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Trackpads Information
Click to Visit
Old 10-14-2005, 13:04   #2 (permalink)
Alan Little
Civilians

 
Default Re: SQL Server: Getting numbers in (right) order

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/
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-14-2005, 13:04   #3 (permalink)
GreyWyvern
Civilians

 
Default Re: SQL Server: Getting numbers in (right) order

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!
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-14-2005, 13:05   #4 (permalink)
George Sexton
Civilians

 
Default Re: SQL Server: Getting numbers in (right) order

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

 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-14-2005, 17:02   #5 (permalink)
Vlad Kozin
Civilians

 
Default Re: SQL Server: Getting numbers in (right) order


"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


 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-17-2005, 09:05   #6 (permalink)
Andy Dingley
Civilians

 
Default Re: SQL Server: Getting numbers in (right) order

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.
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


Community Information
Options
Quick Options
Trackpads Non-Commercial Ad
Copyright Information Click to Visit
Time
Server Time
All times are GMT -4. The time now is 14:23.
Copyright
Copyright Information
The header is based off of work by Vipixel.com and modified by this site. Trackpads and the Trackpads Logo are both Registered Trademarks of Jason Edwards and cannot be used without prior written permission.  The only exception is as a link back to this site. Trackpads is a private website run by a small legion of volunteers, 3 dogs, 12.5 cats and an army of small, super smart, bio-engineered mice with pointy hats and tutu's. Search Engine Friendly URLs by vBSEO 3.2.0 RC7
Archive Links
Archive Links
Page generated in 0.82139 seconds with 19 queries