Curt
Curt

Reputation: 3024

How to do MySQL + Substring? + replace?

something like...

SUBSTRING(table.ProgUID,3,12);

which would give me CAMVE-9701 for the ProgUID P-CAMVE-9701-1 (removing the P- from the beginning and the -1 from the end), and then insert the substring into that rows UID.

I assume this should be fairly easy, and I have been trying to figure it out but havent had much luck.

If there is a better approach please let me know!

Thanks in advance for your thoughts / help!

enter image description here

Upvotes: 2

Views: 2985

Answers (2)

John Woo
John Woo

Reputation: 263893

use UPDATE statement

UPDATE tableName
   SET UID = SUBSTRING(ProgUID,3,12)

Upvotes: 5

ethorn10
ethorn10

Reputation: 1899

If the portion you want is always 12 characters, then

UPDATE table
SET UID = SUBSTRING(ProgUID, 3, 12)

otherwise

UPDATE table
SET UID = SUBSTRING(ProgUID, 3, LENGTH(ProgUID)-2)

Upvotes: 2

Related Questions