Remove last 3 charecters in column

mrrobottelg 60 Reputation points
2024-09-25T07:54:04.8233333+00:00

Hi,

I need to remove three characters(.00) in below table

result:

111111111 without (last three characters i.e .00)

chr
1111111111.00
11111111.00
11111111.00
1111111111.00
1111111.00
111111.00
11111111.00
1111.00
1111111.00
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 27,016 Reputation points
    2024-09-25T08:14:28.4233333+00:00

    Hi @mrrobottelg

    I need to remove three characters(.00) in below table

    You could use the LEFT function like this:

    SELECT LEFT(YourColumn, LEN(YourColumn) - 3) AS ModifiedColumn
    FROM YourTable
    WHERE LEN(YourColumn) > 3;
    

    And update the column to remove the last three characters like this:

    UPDATE YourTable
    SET YourColumn = LEFT(YourColumn, LEN(YourColumn) - 3);
    WHERE LEN(YourColumn) > 3;
    

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 44,501 Reputation points
    2024-09-25T07:58:24.29+00:00

    A simple UPDATE will do the job

    UPDATE YourTable
    SET yourColumn = REPLACE(yourColumn, '.00', '')
    WHERE yourColumn LKIE '%.00'
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.