2

I want to replace all birth that I have from EX : 199500 to 1995 so how can I remove all 2 zeros in my column?

I used this:

select P_BIRTH from city.dbo.personsuly replace(P_BIRTH,00, ,);
2
  • 1
    What data type is that column? Commented Jan 23, 2018 at 8:04
  • Remove 00 doesn't work, consider 199002. Commented Jan 23, 2018 at 8:06

4 Answers 4

3
UPDATE city.dbo.personsuly

SET P_BIRTH = LEFT(P_BIRTH, 4)

When you use LEFT function, you can select a set of charachters from the original column.

Sign up to request clarification or add additional context in comments.

Comments

0

You could use left() function instead of using replace()

select left(P_BIRTH, 4)

Comments

0

You can try this :

select stuff(P_BIRTH, charindex('00', P_BIRTH), 2, '') from city.dbo.personsuly

Comments

0

You can also try like this -

UPDATE city.dbo.personsuly
SET P_BIRTH = P_BIRTH / 100

Example ..This can also work with string data types.

SELECT 199500  / 100

-----------
1995

(1 row affected)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.