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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can one copy first letter of field to another field

Status
Not open for further replies.

jerijeri

Programmer
Sep 11, 2002
33
CA
HI,

I'm wondering if there's a MySQL command/function to copy the first letter of one field to another field.

Thanks,

Jer
 
Insert into table1(field1, field2) values
('value1', substring(field1, 1, 1));


This will fill in the second column with the first letter of the value inserted in the first column.


Bye

Qatqat

The reason why my girlfriend can read my thoughts is because mine are properly written! (G.Lepore)
 
Thank you. I had tried UPDATE with SUBSTRING(field_name,1,1) with no success. Will try this now.

Jer
 
No luck with your suggestion. I should have made it clear that the data is in the table and isn't an insert. This is what I've tried.

UPDATE table SET field_2 = substring(field_1,1,1)

I'm not sure why this wouldn't do what I want.

Jer
 
UPDATE table SET field_2 = substring(field_1,1,1)

updates 1 record. If I try

UPDATE table SET field_2 = substring(field_1,1,1) WHERE id > 1

it updates none. I can't figure what's happening. The field I'm update is set to CHAR(1) and the data it's reading from are all letters.

Jer
 
Well, I found the problem. The query I originally used was fine. I changed

UPDATE table SET field_2 = substring(field_1,1,1)
to
UPDATE table SET field_2 = substring(field_different,1,1)

and it looked just as it should. When I exported the data, I saw a \n as the first character for the field I was trying to import. This was the case except for the very first record.

Jer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top