Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread CASE with float field strips decimal part.
Mon, Mar 21 2011 6:31 PMPermanent Link

Michael Fullerton

EDB 2.04 B4

Hours is a float field. When the query below is run, Total has decimal
values but the day values have the decimal portion truncated. Why is
that?

SELECT WorkDate,
SUM(CASE
  WHEN EXTRACT(DAYOFWEEK FROM WorkDate)=1 THEN HOURS
  ELSE 0
END) AS Mon,
[...]
SUM(CASE
  WHEN EXTRACT(DAYOFWEEK FROM WorkDate)=0 THEN HOURS
  ELSE 0
END) AS Sun, SUM(Hours) AS Total
FROM ETime GROUP BY WorkDate
Tue, Mar 22 2011 3:43 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Michael


I'm guessing that its the same problem I've encountered. With some expressions the parser can't figure out what the result set should be and takes a guess. The solution for me was to wrap the expression in a CAST.

Roy Lambert [Team Elevate]
Tue, Mar 22 2011 11:05 AMPermanent Link

Michael Fullerton

On Tue, 22 Mar 2011 07:43:51 +0000, Roy Lambert
<roy.lambert@skynet.co.uk> wrote:

>Michael
>
>
>I'm guessing that its the same problem I've encountered. With some expressions the parser can't figure out what the result set should be and takes a guess. The solution for me was to wrap the expression in a CAST.

Good guess Roy but unfortunately it didn't work in my CASE.
Tue, Mar 22 2011 12:28 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Michael


Can you post what you attempted?

Roy Lambert [Team Elevate]
Tue, Mar 22 2011 12:35 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Michael


Another little thought went through my mind - change the 0 to 0.0

Roy Lambert [Team Elevate]
Tue, Mar 22 2011 1:47 PMPermanent Link

Michael Fullerton

On Tue, 22 Mar 2011 16:35:47 +0000, Roy Lambert
<roy.lambert@skynet.co.uk> wrote:

>Michael
>
>
>Another little thought went through my mind - change the 0 to 0.0

Yes that's all I had to do, replace all the 0's with 0.0. Thanks Roy.
Wed, Mar 23 2011 5:44 AMPermanent Link

John Hay


> Yes that's all I had to do, replace all the 0's with 0.0. Thanks Roy.

While that is an easy workaround I guess Tim will want to fix this behaviour.

John

Wed, Mar 23 2011 7:45 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

John


He may not be able to. What we have is:

if(condition then datatype1 else datatype2)

what's your guess as to the datatype?

Roy Lambert
Wed, Mar 23 2011 10:28 AMPermanent Link

John Hay

Roy

> He may not be able to. What we have is:
>
> if(condition then datatype1 else datatype2)
>
> what's your guess as to the datatype?

I think there needs to be some sort of type promotion.

What would you expect if you had an expression like 1 + 2.50 ?

I think Michael also said it was returned as a decimal type, so somthing appears to be a bit screwy.

John

Wed, Mar 23 2011 11:35 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

John

>> if(condition then datatype1 else datatype2)
>>
>> what's your guess as to the datatype?
>
>I think there needs to be some sort of type promotion.

Probably but I don't envy whoever has to try and work it out.

>What would you expect if you had an expression like 1 + 2.50 ?

Totally different question - were you ever a politician? Smiley

>I think Michael also said it was returned as a decimal type, so somthing appears to be a bit screwy.

He'd need to clarify what he actually wrote "Total has decimal values but the day values have the decimal portion truncated." which could mean they were returned as integer or as decimal with 0 after the point, or decimal with only 2 places etc.

Roy Lambert [Team Elevate]
Page 1 of 2Next Page »
Jump to Page:  1 2
Image