Anyway to sort such values as 12V like a number.

# Thread: Anyway to sort such values as 12V like a number.

1. Senior Member
Join Date
Dec 1969
Posts
110

## Anyway to sort such values as 12V like a number.

I have a column with such info as voltages, amperages, etc, So the data is in the database as 12V, 2A, 14ns, etc. Is there a way to sort these like a number? If I sort them like strings then 1222V would be &#039;less&#039; then 2V.

2. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Anyway to sort such values as 12V like a numbe

Well I think you have two options, cut off the number and sort by those number, but that&#039;s going to be a performance hit I think.<BR><BR>I think I would add another field to the database: &#039;SortOrder&#039; or something like that. In this field you keep the order in which you want to display the results, but of course it depends on your db design if this is possible...

3. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## and how would you "cut off" the number? <eop&

.

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## Like this

Response.Write CutNumber("12V")<BR><BR>Function CutNumber (strTheText)<BR><BR>iCurrPosition = 1<BR>intLength = Len(strTheText)<BR><BR>Do While iCurrPosition &#060; intLength<BR> If ISNUMERIC(Mid(strTheText, iCurrPosition, 1)) Then<BR> iLastNumberPosition = iCurrPosition<BR> End If<BR> iCurrPosition = iCurrPosition + 1<BR>Loop<BR><BR>CutNumber = LEFT(strTheText,iLastNumberPosition)<BR><BR>END FUNCTION

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## LOL...ok big man

show me how you would do the same in your SQL <BR><BR>who would you SELECT ordered data?<BR><BR>:)<BR>

6. Senior Member
Join Date
Dec 1969
Posts
110

## I'd rather do it in the SQL statement somehow

But that looks to be impossible.

7. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: LOL...ok big man

&#062;&#062; it depends on your design if this works<BR><BR><BR>tblVolts<BR><BR>ID....Volt......O rderBy<BR>1.....12v.......1<BR>2.....24v.......2<B R>3.....110v......3<BR>4.....220v......4<BR>5..... 10000v....5<BR><BR>tblAppliances<BR>ID....Descr... .........VoltID<BR>1.....Electric razor...1<BR>2.....Television.......4<BR>3.....Ele ctric chair...5<BR><BR>SELECT A.ID, A.Descr, V.Volt FROM tblAppliances A INNER JOIN tblVolt V ON A.VoltID = V.ID<BR>ORDER BY V.OrderBy

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•