Trim and Replace Function

burrina

Registered User.
Local time
Today, 03:29
Joined
May 10, 2014
Messages
972
I have almost solved this but I am missing something. The whole Forest because of the Trees thing.

I need to remove 1 final - from my string. Here is my sql.

SELECT tblmaintenance.sernu, Right([sernu],10) AS m10digit, InStr([m10digit],"-") AS [Space]
FROM tblmaintenance;
 
If you want to remove all instances of "-" the you can use:

Code:
Replace([sernu],"-","")

However if if your string has many instances of "-" and you only want to remove the last one then try:

Code:
StrReverse(Replace(StrReverse([sernu]),"-","",1,1))

It works like this:
- reverse the string
- replace the first instance of "-" with empty string
- reverse the string

hth
Chris
 
This code does not make sense to me

Right([sernu],10) AS m10digit, InStr([m10digit],"-") AS [Space]


I susepect you getting the position of '-' whereas I think you need the postion after so try

Code:
Right([sernu],10) , InStrRev([sernu],"-") +1)
 

Users who are viewing this thread

Back
Top Bottom