View Single Post
Old 10-14-2005, 14: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

  Reply With Quote
 
Page generated in 0.66536 seconds with 14 queries