Replace a single character at the end of a string

A

Arts

I have a field in a table named Author where som authors ends with a period
'.' and som do not. Ex. L. Stone. or F. Olsen
I want to put a period at the end of all authors in the table, but only one.
Can anyone help me?
 
R

Rick Brandt

Arts said:
I have a field in a table named Author where som authors ends with a
period '.' and som do not. Ex. L. Stone. or F. Olsen
I want to put a period at the end of all authors in the table, but
only one. Can anyone help me?

UPDATE TableName
SET Author = Author & "."
WHERE Author Not Like "*."
 
R

Roger Carlson

I'd use the Right() function to test the right-most character to see if it's
a period. Something like:

IIF (Right([AuthorName],1)="."), [AuthorName], [AuthorName] & "."

In an Update query, it would look like this:

UPDATE Author SET Authors.AuthorName=
IIf(Right([AuthorName],1)=".",[AuthorName],[AuthorName] & ".");

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
R

Roger Carlson

Dang it, Rick! Why'd you have to go and offer a much more elegant solution?
<grin>
 
R

Rick Brandt

Roger Carlson said:
Dang it, Rick! Why'd you have to go and offer a much more elegant solution?
<grin>

I must admit...I had typed out a solution with Right(Field,1) and was "this
close" to hitting send before I reconsidered it. I'm not sure that execution
times would be any different either way, particularly since this sounded like a
one-off operation anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top