Updated part of a field

  • Thread starter Eleanor of Aquitaine
  • Start date
E

Eleanor of Aquitaine

I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?
 
K

KARL DEWEY

Back up your database. Back up your database.

Use the Replace function --
Replace([YourTableName].[YourFieldName], "answer1", "answer2")
 
M

MGFoster

Eleanor said:
I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

UPDATE table_name
SET column_name = Left(column_name, Len(column_name)-1) & "2"
WHERE column_name IS NOT NULL

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSWfoxIechKqOuFEgEQIhbACg7F++OGnRCqQHPTYbyCNHoYpuvFYAoJH9
kFQ7Svl6YKZwVYRmh51UkdU8
=xxRu
-----END PGP SIGNATURE-----
 
E

Eleanor of Aquitaine

I've only got Access 2003 and I don't think it has the Replace feature.
Sorry, should have mentioned that in the first note.

KARL DEWEY said:
Back up your database. Back up your database.

Use the Replace function --
Replace([YourTableName].[YourFieldName], "answer1", "answer2")


--
KARL DEWEY
Build a little - Test a little


Eleanor of Aquitaine said:
I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?
 
K

KARL DEWEY

Try running a select query with a calculated field like this --
Test_Output: Replace([YourTableName].[YourFieldName], "answer1", "answer2")

--
KARL DEWEY
Build a little - Test a little


Eleanor of Aquitaine said:
I've only got Access 2003 and I don't think it has the Replace feature.
Sorry, should have mentioned that in the first note.

KARL DEWEY said:
Back up your database. Back up your database.

Use the Replace function --
Replace([YourTableName].[YourFieldName], "answer1", "answer2")


--
KARL DEWEY
Build a little - Test a little


Eleanor of Aquitaine said:
I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?
 
J

John W. Vinson

I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?

You need to update the entire field to a new string which differs only in the
last character. For your specific example - updating a field by replacing its
last character (whatever that character might be) to "2" - you could run an
update query updating Myfield to

Left([Myfield], Len([Myfield]) - 1) & "2"

This will evaluate the length of the field; subtract 1 from that length;
extract that many characters from the string; append a literal character 2.
 
E

Eleanor of Aquitaine

Thanks a lot. That worked beautifully.

KARL DEWEY said:
Try running a select query with a calculated field like this --
Test_Output: Replace([YourTableName].[YourFieldName], "answer1", "answer2")

--
KARL DEWEY
Build a little - Test a little


Eleanor of Aquitaine said:
I've only got Access 2003 and I don't think it has the Replace feature.
Sorry, should have mentioned that in the first note.

KARL DEWEY said:
Back up your database. Back up your database.

Use the Replace function --
Replace([YourTableName].[YourFieldName], "answer1", "answer2")


--
KARL DEWEY
Build a little - Test a little


:

I want to write a query that will update only one character in a field.
Right now the data looks like:
question1_answer1
question2_answer1
question3_answer1

I want it to be:
question1_answer2
question2_answer2
question3_answer2

So I just want to change the last character. Is this possible?
 
Top