Share via

Logic needed - kindly help!

SELVAKUMAR VELU 1 Reputation point
2021-09-20T12:24:11.617+00:00

Hi,
whats the function or code in tsql for

If a number is => 0.5 then it should be converted to the next number
< 0.5 then it should be the same number

Eg:
0.01 should become 0
80.5 should become 81
800.01 should become 800

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.


2 answers

Sort by: Most helpful
  1. MelissaMa-msft 24,246 Reputation points Moderator
    2021-09-21T01:45:36.533+00:00

    Hi @SELVAKUMAR VELU ,

    Welcome to Microsoft Q&A!

    Please also refer below:

    DECLARE @Amount1 MONEY  
    SET @Amount1 = 0.01  
    DECLARE @Amount2 MONEY  
    SET @Amount2 = 80.5  
    DECLARE @Amount3 MONEY  
    SET @Amount3 = 800.01  
    SELECT CAST(@Amount1 AS INT)  
    SELECT CAST(@Amount2 AS INT)  
    SELECT CAST(@Amount3 AS INT)  
    

    Output:
    133813-output.png

    Best regards,
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. Olaf Helper 47,621 Reputation points
    2021-09-20T12:48:17.957+00:00

    I guess you mean the ROUND function?

    ;with testData as  
        (select 0.01 as val  
         union all select 80.5  
         union all select 800.01)  
    select *, round(val, 0)  
    from testData  
    

    Was this answer helpful?

    0 comments No comments

Your answer

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