Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1st, 1st Floor, 1 ....update them all into 1st 1

Status
Not open for further replies.

ironj32

Technical User
Dec 7, 2006
73
US
I have a field, [_COMPLETE DATABASE].Floor, where i have multiple different formats... 1st, 1st floor, 2nd floor, 1, 2, etc... i would like to format all of the entries to equal 1st, 2nd, 3rd, 4th, 5th, etc... i know i will need to run an update query but am not sure what the SQL should be.
thanks in advance!
 
Use the val function to return just the numeric portion and format accordingly.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Build a function
Code:
Public NumSuffix(Num as Long) As String
   Dim LastDigit As String   
   NumSuffix = "th"
   If Num < 4 Or Num > 20 Then
      LastDigit = Right(Format(Num,"0"), 1)
      Select Case LastDigit
         Case "1":   NumSuffix = "st"
         Case "2":   NumSuffix = "nd"
         Case "3":   NumSuffix = "rd"
      End Select
   End If
End Function

And then
Code:
UPDATE [_COMPLETE DATABASE] 

SET [Floor] = Val([Floor]) & NumSuffix(Val([Floor]))
which should work OK as long as you don't have more than 110 floors.
 
how come when i run the val function i get a "data type mismatch in criteria expression" warning box?

SELECT [_COMPLETE DATABASE].Floor
FROM [_COMPLETE DATABASE]
ORDER BY Val(Floor);


i do have some records in the table that are "Ground", "Main", "Skyway".

would this be causing it?
 
If Floor may hold Null:
ORDER BY Val(Floor & "")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thanks PHV, but that gives me the results just as if i was running a normal select query with no criteria.
i need to get all the records that start out with numbers
3rd, 2nd floor, 1, 12th, etc... and i need them to drop the suffix's
so results will look like 3, 2, 1, 12
 
SELECT Val(Floor & "")
FROM [_COMPLETE DATABASE]
ORDER BY 1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top