If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Can't have aggregate function in expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-09, 09:18
Krvin Krvin is offline
Registered User
 
Join Date: Jul 2009
Posts: 7
Can't have aggregate function in expression

Can't have aggregate function in expression is what I am getting when I try this:
=Avg & Format(Avg (([FFF]-(Avg([FFF]/3600)*3600))/60),"00") & ":" & Format(([FFF] Mod 60),"00")

However if I change it up to:
=Avg ([FFF]/3600)"00") & ":" & Format(Avg (([FFF]-(Avg([FFF]/3600)*3600))/60),"00") & ":" & Format(([FFF] Mod 60),"00")

It removes the issue but does not run it properly.
The result I am looking for is to take a time stamp of minutes (n.xxxx) to format into h:nn:ss but am having no luck.
Thanks in advanced...
Reply With Quote
  #2 (permalink)  
Old 07-15-09, 09:48
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
This should do the trick:
Code:
=Format(Int(FFF / 60) & Int(FFF - Int(FFF / 60) * 60) & (FFF - Int(FFF)) * 60, "00:00:00")
The last part you'll have to figure out if you want to round seconds up or down.

Regards,

Ax
Reply With Quote
  #3 (permalink)  
Old 07-15-09, 09:52
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
Krvin, What Version of DB2 are you using and what is the operating system?

What I would do is calculate each part (hour, minute and second) separately and then concatenate the values to the correct format.

It appears that what you can't do is nest aggregate functions (going by you example).

I am also not sure why you need the AVG function when doing a time conversion.

Can you give an example of what your input is (I am guessing n.xxxx is minutes and seconds but I really don't know). If the xxxx is seconds, do you want to Round the value or Truncate?

After these questions are answered, I might be able to create a working SQL statement.
Reply With Quote
  #4 (permalink)  
Old 07-15-09, 10:25
Krvin Krvin is offline
Registered User
 
Join Date: Jul 2009
Posts: 7
Can't have aggregate function in expression

I am using IBM DB2 v7.2 on Server 2003.
The n.xxxx = minutes with it being broke down into decimal. Also where the FFF is pointing to it is set to: FFF: DateDiff("s",[TEST_PERFORMED],[TEST_ACQUIRED])
This is what I have come up with but still am unable to get a correct result:
=Avg([FFF])*60=Format("00\:00\:00")

Any other thoughts?

Last edited by Krvin; 07-17-09 at 10:01.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On