2

I've got a table with a column. I want to change a part of some strings in the column.

Input

6|Drivers Manuals

BH-EB531

TRST-BACMN-

Desired output

Drivers Manuals

BH-EB531

TRST-BACMN

Below was the code I tired to execute

 select REPLACE(REPLACE(COL, '6|', ''),'-','') FROM Table

Output

Drivers Manuals

BHEB531

TRSTBACMN

the script need to remove '6|' and last character only if it was '-'

Can any one help me to achieve desired output

2
SELECT (
        REPLACE
                (CASE 
                    WHEN RIGHT (COL, 1) = '-' 
                        THEN LEFT(COL, LENGTH(COL) - 1) 
                    ELSE COL
                END, '6|', ''
                )
        )   
FROM Table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.