OldWest OldWest - 2 months ago 7
MySQL Question

Insert a string 3 characters from the start of a concatenated string

Is it possible in MySQL to insert a string three characters from the beginning of a concat() w/out using SET and UPDATE?

I have a concatenation like:

REPLACE(CONCAT(c.data1,c.data2), ' ', '') AS full_concat


and I need to add a "T" three characters from the start of these results.

Before concat:

data1: 330080S
data2: 0380E021


Concat looks like:

330080S0380E021


Should look like:

33T0080S0380E021 (note the T 3rd position in).

Answer

How about:

REPLACE(
    CONCAT(
        SUBSTR(c.data1,0,2),
        'T',
        SUBSTR(c.data1,2),
        c.data2
    )
)
Comments