trim values from left using SQL

后端 未结 5 1863
忘了有多久
忘了有多久 2021-01-28 02:44

I want to trim the characters from the left in my SQL value:

I have the following value:

ABC0005953

How do i trim the value 3 character

5条回答
  •  再見小時候
    2021-01-28 03:14

    SELECT SUBSTRING('ABC0005953', 4, LEN('ABC0005953'))
    

    Start at the fourth character and keep going.

    (Just posting as an alternative to the RIGHT(...) solution.)

    In response to your update, I assume you mean you want to apply the above to your table:

    SELECT SUBSTRING(TABLE.VALUE, 4, LEN(TABLE.VALUE))
    FROM TABLE
    

    From your other question:

    I have the following:

    SELECT DISTINCT

    Left(GIFTHEADER.pID + GIFTHEADER.PID + '-' + Cast(PAYMENTDETAIL.PLINENO as Varchar),18)

    AS TRANSACTIONREF...

    Currently my value looks like this:

    ABC0005953ABC0005953

    I want to simply strip off the first 4 characters from GIFTHEADER.pID

    If you want to remove the first four characters from GIFTHEADER.pID, I would recommend removing them before putting the value into your combined string:

    SELECT DISTINCT
        LEFT(SUBSTRING(GIFTHEADER.pID, 5, LEN(GIFTHEADER.pID) +
            GIFTHEADER.PID +
            '-' +
            Cast(PAYMENTDETAIL.PLINENO as Varchar),18)
        AS TRANSACTIONREF
    

提交回复
热议问题