Why won't this return a decimal?
2,564 Views | 22 Replies
...
gabehcoud
4:49p, 4/17/24
cast(floor(day(T.eff_date - E.eff_date) / 30) *1.0 as DECIMAL (10,2))

gdammit.

will follow rules when i get off my work computer

IIIHorn
4:52p, 4/17/24



Because it has been decimated.



AggieArchitect04
4:56p, 4/17/24
STAFF: please note that OP appears to be hacking the TexAgs mainframe.
gabehcoud
4:57p, 4/17/24
In reply to IIIHorn
peckerhead
Wolfpac 08
5:04p, 4/17/24
More like SQHell, amirite
infinity ag
5:05p, 4/17/24
In reply to gabehcoud
gabehcoud said:

cast(floor(day(T.eff_date - E.eff_date) / 30) *1.0 as DECIMAL (10,2))

gdammit.

will follow rules when i get off my work computer




Quote:

CAST(FLOOR(DATEDIFF(T.eff_date, E.eff_date) / 30.0) AS DECIMAL(10, 2))

gabehcoud
5:26p, 4/17/24
In reply to infinity ag
CAST(FLOOR(DATE_DIFF('day',E.eff_date, T.eff_date) / 30.0) AS DECIMAL(10, 2))

nope, still returns an integer
UmustBKidding
7:52p, 4/17/24
I think the floor is going to always make the result an integer. But this my sleep deprived opinion from my phone while in bed unable to sleep.
gabehcoud
8:03p, 4/17/24
In reply to UmustBKidding
I tried it with/without a hundred different ways. Decided I was being stupid wasting time and just did it as a variable field in the BI tool. Pisses me off when I can't do something with sql that I can do with a simple excel formula.
Lake08
9:33p, 4/17/24
In reply to gabehcoud
gabehcoud said:

I tried it with/without a hundred different ways. Decided I was being stupid wasting time and just did it as a variable field in the BI tool. Pisses me off when I can't do something with sql that I can do with a simple excel formula.


Are u speaking English???
Hehateme1
12:45a, 4/18/24
In reply to Lake08
Lake08 said:

gabehcoud said:

I tried it with/without a hundred different ways. Decided I was being stupid wasting time and just did it as a variable field in the BI tool. Pisses me off when I can't do something with sql that I can do with a simple excel formula.


Are u speaking English???
I think it's Algebraic.
Philo B 93
6:57a, 4/18/24
Actually, I'd like to jump in and take that one, Jimmy, If you don't mind. Recent research has shown that empirical evidence for globalization of corporate innovation is very limited and as a corollary the market for technologies is shrinking. As a world leader, it's important for America to provide systematic research grants for our scientists. I believe strongly there will always be a need for us to have a well-articulated innovation policy with emphasis on human resource development. Thank you.
Cromagnum
7:51a, 4/18/24
In reply to gabehcoud
Seems like your formula keeps solving for 80085
The Fife
8:54a, 4/18/24
It's like reverse polish or some sht. Who knows what it really means?
AgTrip
11:40a, 4/18/24
AgTrip
11:43a, 4/18/24
infinity ag
12:18p, 4/18/24
In reply to gabehcoud
gabehcoud said:

CAST(FLOOR(DATE_DIFF('day',E.eff_date, T.eff_date) / 30.0) AS DECIMAL(10, 2))

nope, still returns an integer

Gemini says this.

Quote:

There are two potential reasons why this expression might not be returning a decimal even though you're casting it to
DECIMAL(10,2)
:
[ol]
  • Integer Division: The part floor(day(T.eff_date - E.eff_date) / 30) performs integer division. This means it will discard any remainder after the division and only return the whole number quotient. Even if the result of day(T.eff_date - E.eff_date)
    is a decimal (due to difference in days being a fraction), dividing by 30 might result in an integer.
  • Unnecessary Casting: Multiplying the result by 1.0 before casting might be redundant. Casting to DECIMAL itself should be enough to convert the result to a decimal data type.
  • [/ol]



    Quote:

    CAST(FLOOR((day(T.eff_date - E.eff_date) / 30.0) * 1.0) AS DECIMAL(10,2))
    -- OR
    CAST(FLOOR(decimal_division(day(T.eff_date - E.eff_date), 30)) AS DECIMAL(10,2))

    Ornlu
    4:01p, 4/18/24
    In reply to Philo B 93
    Philo B 93 said:

    Actually, I'd like to jump in and take that one, Jimmy, If you don't mind. Recent research has shown that empirical evidence for globalization of corporate innovation is very limited and as a corollary the market for technologies is shrinking. As a world leader, it's important for America to provide systematic research grants for our scientists. I believe strongly there will always be a need for us to have a well-articulated innovation policy with emphasis on human resource development. Thank you.
    What you've just said is one of the most insanely idiotic things I have ever heard. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you no points, and may God have mercy on your soul.
    CrottyKid
    6:54p, 4/18/24
    Not enough info.
    We would need the format of those eff date data.
    IIIHorn
    7:03p, 4/18/24


    This has the potential to be more fun than a pi fight.


    gabehcoud
    9:06p, 4/18/24
    In reply to infinity ag
    Hot damn, this works!
    cast((DATE_DIFF('day',E.eff_date, T.eff_date) / 30.04) AS DECIMAL(10, 2))

    still stupid that excel > sql
    BonfireNerd04
    5:31p, 4/19/24
    Replace 30 with 30.0. That will force the use of real division instead of integer division.
    BonfireNerd04
    5:33p, 4/19/24
    And to be pedantic, a month isn't 30 days. The average (across the Gregorian calendar's 400-year cycle) is 30.436875 days.
    CLOSE
    ×
    Cancel
    Copy Topic Link to Clipboard
    Back
    Copy
    Page 1 of 1
    Post Reply
    ×
    Verify your student status Register
    See Membership Benefits >
    CLOSE
    ×
    Night mode
    Off
    Auto-detect device settings
    Off