0

Let's say we have value 2006 and now I want to remove 0 from it and the result is 26.

Value : 2006

After removing 0, the value is : 26

I have tried to replace directly using replace but in some case like using aggregate functions we can not use it directly.

2
  • I have added this question for knowledge. May be some of you guys already know about it. If any of us know well better, than this answer then please add it bellow. you can also add your answer for MySQL, Oracle. Thanks. Commented Apr 30, 2024 at 17:21
  • 1
    The question as it currently stands is useless and much too vague. "Some case", "like", "we can't", no one can work with such vague statements. Please ask a clear, concrete question or delete yours again. Commented Apr 30, 2024 at 17:57

2 Answers 2

2

Example where the replace is used with a grouping function

CREATE TABLE Example 
(
    ID  Int,
    Result  Varchar(4)
);

INSERT INTO Example (ID,Result) VALUES
    (1,'2006'),
    (1,'2007'),
    (1,'2008'),
    (2,'2009'),
    (2,'2010');


SELECT ID, 
       MAX(Result) as maxresult, 
       MAX(REPLACE(Result,'0','')) as MaxResultWithoutZeros 
FROM Example
GROUP BY ID

fiddle

ID maxresult MaxResultWithoutZeros
1 2008 28
2 2010 29
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for giving broad view for understanding it is better.
1

For Microsoft SQL Server

SELECT CONVERT(integer, REPLACE(2006,'0', ''));

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.