check if fraction

Thirston Third 21 Reputation points
2022-03-31T15:16:01.667+00:00

How do you check if this is a fraction?
select 72/5

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,575 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Naomi 7,361 Reputation points
    2022-03-31T15:30:05.517+00:00

    Is it what you're after?

    SELECT 72/5, CASE WHEN 72%5=0 THEN 'No fraction' ELSE 'Fraction' end

    Using modulus operation?

    0 comments No comments

  2. Guoxiong 8,126 Reputation points
    2022-03-31T15:31:18.95+00:00

    Do you mean this:

    SELECT CASE WHEN 72 % 5 = 0 THEN 0 ELSE 1 END [Fraction];  
    

    188806-image.png

    0 comments No comments

  3. LiHong-MSFT 10,046 Reputation points
    2022-04-01T02:56:21.643+00:00

    Hi @
    In SQLSever, if 2 ints are /, it will return int.If you want the result to become float,you may multiply one of the INTs by 1.0
    Check this:

    SELECT 72 / 5,  
           1.0 * 72 / 5  
    

    Best regards,
    LiHong


    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".
    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.

    0 comments No comments