Why won't this return a decimal?

2,480 Views | 22 Replies | Last: 13 days ago by BonfireNerd04
gabehcoud
How long do you want to ignore this user?
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
How long do you want to ignore this user?



Because it has been decimated.



AggieArchitect04
How long do you want to ignore this user?
AG
STAFF: please note that OP appears to be hacking the TexAgs mainframe.
gabehcoud
How long do you want to ignore this user?
peckerhead
Wolfpac 08
How long do you want to ignore this user?
AG
More like SQHell, amirite
infinity ag
How long do you want to ignore this user?
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
How long do you want to ignore this user?
CAST(FLOOR(DATE_DIFF('day',E.eff_date, T.eff_date) / 30.0) AS DECIMAL(10, 2))

nope, still returns an integer
UmustBKidding
How long do you want to ignore this user?
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
How long do you want to ignore this user?
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
How long do you want to ignore this user?
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
How long do you want to ignore this user?
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
How long do you want to ignore this user?
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
How long do you want to ignore this user?
AG
Seems like your formula keeps solving for 80085
The Fife
How long do you want to ignore this user?
It's like reverse polish or some sht. Who knows what it really means?
AgTrip
How long do you want to ignore this user?
AgTrip
How long do you want to ignore this user?
infinity ag
How long do you want to ignore this user?
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
    How long do you want to ignore this user?
    AG
    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
    How long do you want to ignore this user?
    AG
    Not enough info.
    We would need the format of those eff date data.
    IIIHorn
    How long do you want to ignore this user?


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


    gabehcoud
    How long do you want to ignore this user?
    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
    How long do you want to ignore this user?
    Replace 30 with 30.0. That will force the use of real division instead of integer division.
    BonfireNerd04
    How long do you want to ignore this user?
    And to be pedantic, a month isn't 30 days. The average (across the Gregorian calendar's 400-year cycle) is 30.436875 days.
    Refresh
    Page 1 of 1
     
    ×
    subscribe Verify your student status
    See Subscription Benefits
    Trial only available to users who have never subscribed or participated in a previous trial.