Discoverer Sum Hours
Hi all
I'm having a problem creating a 'sum' of Hours in discoverer. The column displays hours in a HH:MI format, this is calculated from a DB column which contains decimal hours e.g. (1 hour and 30 mins is stored as 1.5 hours) these should be added together by the discoverer sum/cell sum item and displayed at the bottom of the report (a grand total).
- I cant find a way of applying any code / formatting to a sum to convert from decimal to HH:MI
- I also cant find a way of discoverer performing a sum on the Hours:Minuts format, (as its text) or apear to be able to turn this into a date/other data type as the date format is limited to 24 hours 59 mins etc and the total can be any amount of hours/mins and a number gets me back to square one.
Is there a way around this in discoverer, is there a way of creating a custom sum function or similar or am i missing knowledge of a data type?
Any help you can give would be appreciated
-Sol
On your total, do the Format Data button. On the Format Data window, pick the Number tab. In the categories window on the Number tab, pick the Custom value. That should give you a several custom formats to see and pick from, including a HH:MM:SS format. I think you can create new custom format types, but I have not personally done that. Maybe someone who has will explain that process. Not sure how well this will work - you are doing something that I have never attempted to do before. But you can play around and see if it might work. I don't see an HH:MM in my custom list though, which is what you seem to be needing (which would mean defining a new customr format, if possible). You may have to go to Oracle support on this, and perhaps end up submitting an enhancement request.
John Dickey
Similar Messages
-
How to sum hours which is varchar2 data type in oracle
Hi My table is like this
emp_ngtshthrs (empno number(10),nightshifthrs varchar2(20));
now I want sum employee nightshifthrs how to do sum of hrs, this is my hours data 01:00,05:00,08:00,10:00,07:00 and 09:00
I want sum the varchar2 type of hours how to do it? and I want to display even the sum is more than 24:00 hrsWell, first you have posted your question in the wrong forum. You should have posted your question in the PL/SQL forum.
The second problem I see is that you are being too generic when you have your employees enter their night shift hours worked. If you are able, I recommend you modify your table to record hours seperately from minutes and make the columns of type NUMBER instead of type VARCHAR2(). Then you can use simply arithmatic to total the hours and minutes worked.
If you are locked into your table and can't change it, then you can convert the characters to numbers and then perform your summary arithmatic on the values. For example:
1 with tab1 as (
2 select 10 as empno, '01:00' as nightshifthrs from dual union all
3 select 10 as empno, '05:00' as nightshifthrs from dual union all
4 select 10 as empno, '08:00' as nightshifthrs from dual union all
5 select 10 as empno, '10:00' as nightshifthrs from dual union all
6 select 10 as empno, '07:00' as nightshifthrs from dual union all
7 select 10 as empno, '09:00' as nightshifthrs from dual)
8 select sum(to_number(replace(nightshifthrs,':','.'))) AS hours_worked
9* from tab1
SQL> /
HOURS_WORKED
40
SQL> Of course, if your users can and do enter minutes, then that complicates the example I provided. You will have to convert the minutes to decimal, sum the amount, then convert the decimal back to time and add this to your hours. For example:
1 with tab1 as (
2 select 10 as empno, '01:15' as nightshifthrs from dual union all
3 select 10 as empno, '05:00' as nightshifthrs from dual union all
4 select 10 as empno, '08:30' as nightshifthrs from dual union all
5 select 10 as empno, '10:00' as nightshifthrs from dual union all
6 select 10 as empno, '07:45' as nightshifthrs from dual union all
7 select 10 as empno, '09:00' as nightshifthrs from dual)
8 select sum(to_number(substr(nightshifthrs,1,2))) + SUM(to_number(SUBSTR(nightshifthrs,4,5)))/60
9* from tab1
SQL> /
HOURS_WORKED
41.5
SQL> Hope this helps.
Craig... -
Looping through date column - Summing hours per day
All,
Running the query below against my timesheet tables I get the following results:
-----SQL CODE------
SELECT
ts.ts_date Date,
ts.user_name Name,
tc.account Account,
ts.no_of_hrs Hours,
SUM(ts.no_of_hrs) OVER(PARTITION BY ts.ts_date) Daily_Total
FROM
eba_time_timesheet ts,
eba_time_timecodes tc
WHERE
ts.timecode_id = tc.id AND
ts.user_name LIKE 'JohnD'
ORDER BY
1
-----RESULTS-------
Date Name Account Hours Daily Total
1-Dec-09 JOHND 489310 1.5 8
1-Dec-09 JOHND 486830 1.5 8
1-Dec-09 JOHND 481710 3 8
1-Dec-09 JOHND 481210 0.5 8
1-Dec-09 JOHND 486840 0.5 8
1-Dec-09 JOHND 485710 0.5 8
1-Dec-09 JOHND 481010 0.5 8
2-Dec-09 JOHND 481710 1 8
2-Dec-09 JOHND 485710 7 8
3-Dec-09 JOHND 481710 6 8
3-Dec-09 JOHND 488810 1.5 8
3-Dec-09 JOHND 481310 0.5 8
4-Dec-09 JOHND 489710 8 8
7-Dec-09 JOHND 481110 0.5 8
7-Dec-09 JOHND 489710 7 8
7-Dec-09 JOHND 481210 0.5 8
However, I would prefer the Daily Total column be a row in the results instead of a column. Here is an example of how I would prefer the results. This statement will then be sent to a calendar for each user to see there time for each account and total time per day.
Date Name Account Hours
1-Dec-09 JOHND 489310 1.5
1-Dec-09 JOHND 486830 1.5
1-Dec-09 JOHND 481710 3
1-Dec-09 JOHND 481210 0.5
1-Dec-09 JOHND 486840 0.5
1-Dec-09 JOHND 485710 0.5
1-Dec-09 JOHND 481010 0.5
*1-Dec-09 JOHND Daily Total 8*
2-Dec-09 JOHND 481710 1
2-Dec-09 JOHND 485710 7
*2-Dec-09 JOHND Daily Total 8*
3-Dec-09 JOHND 481710 6
3-Dec-09 JOHND 488810 1.5
3-Dec-09 JOHND 481310 0.5
*3-Dec-09 JOHND Daily Total 8*
4-Dec-09 JOHND 489710 8
*4-Dec-09 JOHND Daily Total 8*
7-Dec-09 JOHND 481110 0.5
7-Dec-09 JOHND 489710 7
7-Dec-09 JOHND 481210 0.5
*7-Dec-09 JOHND Daily Total 8*
Any help would be greatly appreciated.
This is my 1st post so if I've left something out or you need additional info please let me know.
I’m using Oracle 10guser9160575 wrote:
Thanks for all the input! I ended up using the GROUP BY ROLLUP and adding a CASE statement for inserting "DAILY TOTAL" in the account column.If you are on at least 10g, model solution could be simpler:
with t as (
select to_date('1-Dec-09','dd-mon-yy') dt,'JOHND' name,489310 account,1.5 hours,8 daily_total from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',486830,1.5,8 from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',481710,3,8 from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',481210,0.5,8 from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',486840,0.5,8 from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',485710,0.5,8 from dual union all
select to_date('1-Dec-09','dd-mon-yy'),'JOHND',481010,0.5,8 from dual union all
select to_date('2-Dec-09','dd-mon-yy'),'JOHND',481710,1,8 from dual union all
select to_date('2-Dec-09','dd-mon-yy'),'JOHND',485710,7,8 from dual union all
select to_date('3-Dec-09','dd-mon-yy'),'JOHND',481710,6,8 from dual union all
select to_date('3-Dec-09','dd-mon-yy'),'JOHND',488810,1.5,8 from dual union all
select to_date('3-Dec-09','dd-mon-yy'),'JOHND',481310,0.5,8 from dual union all
select to_date('4-Dec-09','dd-mon-yy'),'JOHND',489710,8,8 from dual union all
select to_date('7-Dec-09','dd-mon-yy'),'JOHND',481110,0.5,8 from dual union all
select to_date('7-Dec-09','dd-mon-yy'),'JOHND',489710,7,8 from dual union all
select to_date('7-Dec-09','dd-mon-yy'),'JOHND',481210,0.5,8 from dual
select dt "Date",
name "Name",
account "Account",
hours "Hours"
from t
model
dimension by(dt,name,to_char(account) account)
measures(hours,daily_total,0 seq)
rules upsert all(
hours[any,any,'Daily Total'] = max(daily_total)[cv(dt),cv(name),any],
seq[any,any,'Daily Total'] = 1
order by dt,
name,
seq,
account
Date Name Account Hours
01-DEC-09 JOHND 481010 .5
01-DEC-09 JOHND 481210 .5
01-DEC-09 JOHND 481710 3
01-DEC-09 JOHND 485710 .5
01-DEC-09 JOHND 486830 1.5
01-DEC-09 JOHND 486840 .5
01-DEC-09 JOHND 489310 1.5
01-DEC-09 JOHND Daily Total 8
02-DEC-09 JOHND 481710 1
02-DEC-09 JOHND 485710 7
02-DEC-09 JOHND Daily Total 8
Date Name Account Hours
03-DEC-09 JOHND 481310 .5
03-DEC-09 JOHND 481710 6
03-DEC-09 JOHND 488810 1.5
03-DEC-09 JOHND Daily Total 8
04-DEC-09 JOHND 489710 8
04-DEC-09 JOHND Daily Total 8
07-DEC-09 JOHND 481110 .5
07-DEC-09 JOHND 481210 .5
07-DEC-09 JOHND 489710 7
07-DEC-09 JOHND Daily Total 8
21 rows selected.
SQL> SY. -
Can't sum Hours:Minutes:Seconds
Hi,
iam working on to get the sum of overtimes,late coming and early going.actually i have the 3 fields for overtime, late, early and at the end of the month i want to get the summary of these fields in format of hh:mi:ss.For ex. in overtime i may have different values for different days in format of hh:mi:ss and i want to calculate the summary of overtime for complete month. and i am using sum function but its giving me the error as invalid number.Please help me in this scenario.
Thanks
PremShould you be storing intervals instead of varchar2?
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/expressions009.htm#SQLRF52084
With intervals you will have a problem that sum function supports only numeric as a parameter. Invalid number as you noticed. Intervals are not supported. You should implement your own interval aggregate.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10765/aggr_functions.htm#ADDCI026 and an example of a user defined aggregate may be found from http://rafudb.blogspot.com/2011/03/greatest-common-divisor.html Not a interval one thou.
Or maybe do the dirty work by summing seconds and after that calculating the presentation like you want.
with time_table as (
select '01:01:01' time_val from dual union all
select '00:59:01' time_val from dual union all
select '23:59:59' time_val from dual
select s
, trunc(s/(60*60))||':'||lpad(mod(trunc(s/60),60),2,'0')||':'||lpad(mod(s,60),2,'0') time_sum
from (
select sum(substr(time_val,1,2)*60*60+substr(time_val,4,2)*60+substr(time_val,7,2)) s
from time_table
93601 26:00:01 -
Help in doing sum fields from tables
HALLOW
i have a table and i wont to add the tables line to one line , to do sum
if date appear more then one time like in example.
i give example
date----
hours
01.01.2002 6.5
01.01.2002 2.5
02.01.2002 5
03.01.2002 3
03.01.2002 3
04.01.2002 4
06.01.2002 5
i wont to move it to table like this
date----
hours
01.01.2002 9 ->sum houres of date 01.01.2002
02.01.2002
03.01.2002 6 ->sum houres of date 03.01.2002
04.01.2002 4
06.01.2002 5
Regards
i rewardYou can get same functionality if you use Internal table events .
See the simple example :
*& Report ZTEST_IEVENTS
REPORT ZTEST_IEVENTS no standard page heading
line-count 40(2).
tables : vbap.
data : begin of i_vbap occurs 0,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
netpr like vbap-netpr,
end of i_vbap.
data wa_vbap like line of i_vbap.
data v_flag type c.
select-options s_vbeln for vbap-vbeln obligatory.
start-of-selection.
select vbeln
posnr
matnr
kwmeng
netpr from vbap
into table i_vbap
where vbeln in s_vbeln.
sort i_vbap by vbeln posnr.
end-of-selection.
loop at i_vbap.
move i_vbap to wa_vbap.
at first.
write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.
skip 1.
endat.
at new vbeln.
write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,
47 wa_vbap-kwmeng,65 wa_vbap-netpr.
v_flag = 'X'.
endat.
if v_flag ne 'X'.
write:/15 wa_vbap-posnr,28 wa_vbap-matnr,
47 wa_vbap-kwmeng,65 wa_vbap-netpr.
endif.
at end of vbeln.
sum.
skip 1.
write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.
skip 1.
endat.
at last .
skip 1.
sum.
write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.
skip 1.
write:/ 'end of page', 'Footer'.
endat.
clear v_flag.
endloop.
Good luck
Thanks
Seshu -
hello,
In rdlc report i need to sum the date time datatype .
please help .
thanks.Hi Krishnakumar_Dev,
If we want to extract hour in a date time field, we can use hour function as below in Reporting Services.
=sum(hour(Fields!date.Value))
Besides, if this issue is still existed, Could you please post the screenshot about your dataset with sample data and desired result?
For more information about Date and Time Functions, please refer to the following link:
http://technet.microsoft.com/en-us/library/aa337153(v=sql.100).aspx
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Hi,
I have two Dimensions in the fact, these are Dim_Quarter and Dim_Region. Dim_Quarter has two levels i.e. Year and Quarter with Hierarchy Year --> Quarter, and Dim_Region follows the Hierarchy Region --> State -> District.
Now I want the Snapshot functionality for measures when we Roll Up from Quarter to Year i.e when we roll up from Quarter to Year, i need to display the value of Quarter four(Q4) against the measure not the aggregated value as done by default in discoverer.
Can anyone please tell me how to proceed on this.
Any Help is appreciable.
Thanks and Regards
Mukesh Harjai.Hi All,
Can anybody help me out in solving this problem. I need that the value against Quarter four(Q4) should be displayed for a measure when i roll up from Quarter to Year. Discoverer Sum up values for all quarters when we roll up.
Please Help
Thanks and Regars -
I am doing something and I believe I am doing it quite wrong. When I plug the data into a light switch app in Visual Studio, I get a JSON error. I am getting my data every 15 minutes. I need to present this data by the hour. Here is my design at the
moment. It works fine until you try to use it in the Light switch app. I keep thinking there has to be a more efficient way to do this then how I am doing it.
Here, I am taking the data from the export, converting the time, and pulling the Channel data I need, then sum hourly usage.
SELECT TOP (100) PERCENT p_mtrid AS MeterID, p_mtrchn AS Channel, DATEPART(Month, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2)
+ ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)) AS Month, DATEPART(day, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2)
+ ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)) AS Day, DATEPART(year, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2)
+ ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)) AS Year, DATEPART(hour, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2)
+ ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)) AS Hour, CONVERT(decimal(10, 4), SUM(p_usage)) AS HourlyUsage
FROM dbo.utsProfile
GROUP BY p_mtrid, p_mtrchn, DATEPART(Month, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2) + ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)),
DATEPART(day, CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2) + ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)), DATEPART(year,
CAST(SUBSTRING(p_dtm, 1, 8) + ' ' + SUBSTRING(p_dtm, 9, 2) + ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime)), DATEPART(hour, CAST(SUBSTRING(p_dtm, 1, 8)
+ ' ' + SUBSTRING(p_dtm, 9, 2) + ':' + SUBSTRING(p_dtm, 11, 2) AS SmallDateTime))
HAVING (p_mtrchn = 1)
ORDER BY MeterID, Month, Day, Year, Hour
Then I convert it back to SmallDateTime and put all 3 channels together.
SELECT TOP (100) PERCENT dbo.HourlyKWH.MeterID, CONVERT(SmallDateTime, CAST(dbo.HourlyKWH.Month AS VARCHAR(2))
+ '-' + CAST(dbo.HourlyKWH.Day AS VARCHAR(2)) + '-' + CAST(dbo.HourlyKWH.Year AS VARCHAR(4)) + ' ' + CAST(dbo.HourlyKWH.Hour AS VARCHAR(2)) + ':00')
AS DateTime, CONVERT(decimal(10, 4), dbo.HourlyKWH.HourlyUsage) AS KWH, CONVERT(decimal(10, 4), dbo.HourlyKVAH.HourlyUsage) AS KVAH,
CONVERT(decimal(10, 4), dbo.HourlyKVARH.HourlyUsage) AS KVARH
FROM dbo.HourlyKWH INNER JOIN
dbo.HourlyKVAH ON dbo.HourlyKWH.MeterID = dbo.HourlyKVAH.MeterID AND dbo.HourlyKWH.Month = dbo.HourlyKVAH.Month AND
dbo.HourlyKWH.Day = dbo.HourlyKVAH.Day AND dbo.HourlyKWH.Year = dbo.HourlyKVAH.Year AND dbo.HourlyKWH.Hour = dbo.HourlyKVAH.Hour INNER JOIN
dbo.HourlyKVARH ON dbo.HourlyKWH.MeterID = dbo.HourlyKVARH.MeterID AND dbo.HourlyKWH.Month = dbo.HourlyKVARH.Month AND
dbo.HourlyKWH.Day = dbo.HourlyKVARH.Day AND dbo.HourlyKWH.Year = dbo.HourlyKVARH.Year AND dbo.HourlyKWH.Hour = dbo.HourlyKVARH.Hour
ORDER BY dbo.HourlyKWH.MeterID, DateTime
This is presenting the data the way I need it to look but, I cannot use it in lightswith. JSON error. Is there a better way to SUM usage by using DATEPART?
Thank you very much in advance. I might need to read over this and reword it.Hi,
There is nice forum on Visual Studio LightSwitch - General Questions :
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=lightswitch
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/ -
Minutes and hours query problem
I've got the following query in my app:
SELECT NAME,
SUM(HOURS)+SUM(MINUTES/60)-SUBSTR(TO_CHAR((SUM(MINUTES/60)),'9999D00'),6,3) AS"HOURS",
MOD(SUM(MINUTES),60) AS"MINUTES",
SUM(OVERTIME_HOURS)+SUM((OVERTIME_MINUTES/60))-SUBSTR(TO_CHAR(SUM((OVERTIME_MINUTES/60)),'9999D00'),6,3) AS"OT HOURS",
MOD(SUM(OVERTIME_MINUTES),60) AS"OT MINUTES",
SUM (STAT) AS "STAT",
SUM(HOURS + (MINUTES/60) + (OVERTIME_HOURS*1.5) + ((OVERTIME_MINUTES/60)*1.5) + STAT)-SUBSTR(TO_CHAR(SUM((MINUTES/60)+((OVERTIME_MINUTES/60)*1.5)),'9999D00'),6,3) AS "TOTAL HOURS",
MOD(SUM(MINUTES+(OVERTIME_MINUTES*1.5)),60) AS"TOTAL MINUTES"
FROM KTT_INFORMATION
WHERE DAY BETWEEN (:P15_FROM_DATE) AND (:P15_TO_DATE)
GROUP BY NAME
I want the hours and minutes to display as hours in one column and the remaining minutes in the next column. The minutes are only 15,30 or 45 in the table. For some reason one of the hours columns is giving an output with a decimal. Where the output should be 191 hours and 45 minutes I'm getting 191.5 hours and 15 minutes.
Any ideas?create or replace function get_time(p_time number)
return varchar2
is
v_time varchar2(20);
begin
v_time:=to_char(trunc(mod(p_time,3600)/60), 'FM00') || ':' || to_char(mod(p_time,60), 'FM00');
return (v_time);
exception
when others then
return null;
end get_time;
show errors;
i created a function which converts given minutes into hrs and min.
then i created a tem table and trying to insert hrs into one column and min into anothere column.
CREATE TABLE TEMP
TIME NUMBER(3) NOT NULL,
HRS NUMBER(3) NOT NULL,
MIN NUMBER(3) NOT NULL
insert into temp values (150,substr(get_time(150),1,2) ,substr(get_time(150),4,5))
hope this may be helpful to you.
sudhir. -
Returning total sum plus pivoted sums in same result set
I want to return a result set in the following format:
YEARMONTH Total ModelA ModelB ModelC
200101 0 0 0 0
200102 10 5 5 0
200103 8 2 2 4where the total is the sum of the hours for all model types grouped by yearmonth, and the individual model columns are the sum of hours per model type grouped by yearmonth. I can get the correct results using the following query with nested selects:
select distinct yearmonth,
sum(a.hours) as Total,
(select sum(b.hours) from model_hours b
where model = 'ModelA' and a.yearmonth = b.yearmonth) as ModelA,
(select sum(b.hours) from model_hours b
where model = 'ModelB' and a.yearmonth = b.yearmonth) as ModelB,
(select sum(b.hours) from model_hours b
where model = 'ModelC' and a.yearmonth = b.yearmonth) as ModelC
from model_hours a
group by yearmonth
order by yearmonthI was curious to try using the pivot function in Oracle 11 to achieve the same results, and am able to get all the results EXCEPT the total hours using the following query:
select * from (
select yearmonth, hours, model
from model_hours a
pivot
sum(hours)
for model in ('ModelA', 'ModelB', 'ModelC')
order by yearmonthwhich returns this result:
YEARMONTH ModelA ModelB ModelC
200101 0 0 0
200102 5 5 0
200103 2 2 4I have not been able to figure out how to also get the sum of the hours for all models, grouped by yearmonth, into this resultset. Is it possible? And if so, would it be likely to be more efficient than the nested selects? This particular table has some 200K rows right now.Hi,
923402 wrote:
Frank, thank you so much. I added a bunch of nvl() functions and it works now. Didn't have a chance to try it with the other answer but it looks like it would be similar.
I'm still curious as to whether doing it this way is more efficient than my original query, using nested selects.Definitely! Scalar sub-queries, like you did in your first message, will require multiple passes through the table. SELECT ... PIVOT only requires one.
Here's another way that should be as efficient as SELECT ... PIVOT:
SELECT yearmonth
, SUM (hours) AS total
, NVL (SUM (CASE WHEN model = 'ModelA' THEN hours END), 0) AS modela
, NVL (SUM (CASE WHEN model = 'ModelB' THEN hours END), 0) AS modelb
, NVL (SUM (CASE WHEN model = 'ModelC' THEN hours END), 0) AS modelc
FROM model_hours
GROUP BY yearmonth
ORDER BY yearmonth
;The NVLs are only necessary for display; you don't need them to get the correct total.
I don't have access to a SQL efficiency testing program; otherwise, I'd test it myself; if you don't think you can answer I'll just give it to our overworked DBA. Ask your DBA if you can use EXPLAIN PLAN. -
To display Days Hours Mins Format based on business hours
Hi,
I want to display Days Hours Mins Format.
I am Having two columns Like below,
Col1 (in days) col2 (In Hours : Mins)
3days 4:5
In this first have to add Col1 and Col2 (Here one day is equals to
9 hours ) so the addition is 31.5
from this 31.5 i should display 3 Days 4 Hours 30 Mins because 31.5 contains 3 (9 hours) days 4 Hours and .5 is equals to 30 mins.
Kindly please help me in this,
thanks in advance.
GVRSPK VENIHello gvespk,
Regarding your description, are you looking for some sample as below?
DECLARE @T TABLE
ID VARCHAR(99),
SubID INT,
Days INT,
Hours FLOAT
INSERT INTO @T VALUES
('abz', 1, 2, null)
,('abz', 2, null, 3 )
,('abz', 3, 3, 4 )
,('abz', 4, null, null )
,('abz', 5, 2, null )
,('abz', 6, 1, 5 )
,('abz', 7, null, 2 )
,('abz', 8, null, null )
,('abz', 9, 2, 3 )
,('abz', 10, null, 2.5 );
SELECT SUM(DAYS)+FLOOR(SUM(HOURS)/9) DAYS
, FLOOR(SUM(HOURS)-FLOOR(SUM(HOURS)/9)*9) AS HOURS
, (SUM(HOURS)-FLOOR(SUM(HOURS)))*60 MINUTES FROM @T
DAYS HOURS MINUTES
12 1 30
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
Hi all,
I have data in the following manner:
CASE_NUMBER HOURS FLAG
1000 10 0
1000 20 0
1000 30 1
1000 40 0
1000 50 1
Here I need to Calculate the total hours for a Case_number till i see the flag as 1.
Here the result must be 10+20+30 Hrs
Another Example
CASE_NUMBER HOURS FLAG
2000 10 1
2000 20 1
Here the result must be only 10.
I am struggling to write a SQL query for this.
Anyones help will be very much greatful
Thanks in Advance
Regards,
Sengathir SubbarayanLook up analytical functions.
something like sum(hours) OVER (PARTITION BY case_number ORDER BY something)
will give you the sum for all rows.
Then you probably want to "throw away" those rows after the flag maybe by summing the flag column too, and throw away all those where the flag is greater than 1 and where it is equal to 1 except for the first one.
I suspect you actually have some other column (other than the number of hours) that define your order - that's what you put in the ORDER BY.
Jon -
Passing multi-value parameter in stored procedure ssrs
I have customer parameter which is a drop down list in my report and I have set it to "allow multiple values". This is an SSRS report.
How do I pass multiple values to my stored procedure?
RJHi ,
Create a Table valued function in SQL Functions as below
Step 1
CREATE FUNCTION [dbo].[FnSplit]
@List nvarchar(2000),
@SplitOn nvarchar(5)
RETURNS @RtnValue table
Id int identity(1,1),
Value nvarchar(100)
AS
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End
Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END
Step 2 in your store procedure change the parameter where condition something like below
ALTER PROCEDURE [dbo].[SomeSP]
-- Add the parameters for the stored procedure here
@CostCentre NVARCHAR(255)
SELECT
[ProjectCode],[ProjectName],[ProjectManager],SUM([Hours]) AS [Hours MTD]FROM dbo.Rpt_NRMA_CATS NC
INNER JOIN PeriodID P ON NC.PeriodID=P.PeriodID
WHERE
([CostCentre]) collate database_default IN(SELECT Value FROM dbo.FnSplit(@CostCentre,','))
END
I hope this will help you.
Dasari -
Calculated variable throwing #MULTIVALUE error
I have data of employees entering time by day and time can be billable and non-billable.
I want to show a column chart where I show the number of employees categorized as per following buckets based on their NB%
"75% and Above", "50-75%" and "0-50%"
To achieve this I created a variable (measure) first that calculates the NB% and then created another variable called NB Group which basically is a set of If, ElseIf conditions that check NB% and assign value as "75% and Above", "50-75%" and "0-50%".
When I create a report with columns employee, NB% and NB Group, the NB Group value shows up fine. However when I just pull NB Group into a blank report I am getting #MULTIVALUE error.
I was expecting to see a distinct list of all the NB Groups just like it would for any other dimension and then wanted to add a new column with count of employees and convert that into a chart.
What am i doing wrong? Is there another approach I should follow?Both [Hours] and [Non-Billable Hrs] are report level variables.
[Hours] = [Hours Entered] + [Hours Missing] (Both of these are coming from the DB/Universe)
[Non-Billable Hrs] =Sum([Hours]) In ([Employee]) Where ([Hrs Type] = "Non-Billable")
[NB Group] =If [Non-Billable Hrs]/ Sum([Hours]) > 0.5 Then "50% and Above" Else "0-50%"
Note: [NB Group] is getting converted to a measure automatically and i am not able to change it. Wondering if this is causing the problem?
Anyway, as you suggested I tried to take a small data set and get the results per Employee and that came out correctly (top table).
However, when I remove the employee and try to aggregate I am not getting the expected count.
Here, Employee =Count([Employee]) -
ORA-06502 (character string buffer too small) on import application via script
Running apex 4.2.2.00.11
oracle 10.2.0.5
I'm using a script to import my development application to a few production applications.
It worked great on apex 4.1.1, but now I get an 'ORA-06502 PL/SQL numeric of value error: character string buffer too small'
In the command window, I see that the script fails after it starts on the plugins.
My question: is this a bug in 4.2.2?
I could be a incompatible plugin, but how can I found out which plugin?
My script is quite simple:
In a command window I run
sqlplus SCHEMA/PASSWORD@SPIEU10 @_IMPORT_F102.sql
The script is
declare
l_workspace_id number;
begin
-- determine the workspace id for the workspace FM in the target system
select workspace_id into l_workspace_id from apex_workspaces where workspace = 'BY_APEX_SHARED';
-- set the context for the target workspace
apex_application_install.set_workspace_id( l_workspace_id );
-- override the original application id 102
apex_application_install.set_application_id ( 102 );
-- set a different application name and alias, it should be unique within an APEX instance
apex_application_install.set_application_alias( 'MY_ALIAS' );
apex_application_install.set_application_name( 'MY_APP_NAME' );
-- Use fixed offset
apex_application_install.set_offset( p_offset => 0);
-- override the original parsing schema FM with a different value
apex_application_install.set_schema( 'BY_SCHEMA' );
end;
-- install the original application export, now the values for the workspace
@f102.sql
exit;
Error message from command window:
...ui types
...plugins
begin
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 3
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64
bit Production
With the Partitioning, Data Mining and Real Application Testing optionsListAGG throws an ORA-01489 for varchar2 > 4000 bytes
OP has an ORA-06502 --> the IR is running into a 4k/32k limit.
quick solution: wrap USER_COMMENTS ListAGG in a substr( ...., 1, 4000)
Longer solution, use a subquery to modify the comments based on ROW_NUMBER() (ie after nth row, change it to NULL)
with
-- simulating data
t as (select task_id, sysdate - lv as date_entered
,round(dbms_random.value(1,24)) hours
, '-*' || lv || '.' || task_id || '*-' as user_comments
from ( select level as task_id from dual connect by level <=10 ), (select level lv from dual connect by level < 1000)
-- modify data
modified_data as (
select task_id, hours, date_entered
,case
when row_number() over (partition by task_id order by date_entered desc) < 5
then user_comments
else null
end USER_COMMENTS
from t)
select task_id, sum(hours) total_hours,
listagg( user_comments ) within group (order by date_entered desc)
|| case when count(*) >= 5 then '! MORE COMMENTS !' else null end
as user_comments
from modified_data
group by task_id;
Maybe you are looking for
-
Match code in customised table
Hi, I created a ztable and my further requirments is for particular field there will be a only three options that user will enter only N ,S or D.if the user enter other than that it should show the error message "Pls enter correct word".so pls he
-
CP5 - Continue action not working
I am pretty sure this was working last week and now its not. The set up is that I hide the playbar on page enter (assign-->cpCmndShowPlaybar=0), then there is a click box that suppose to show the playbar and continue after the 1st incorrect try via a
-
How do i see the thumbnails when using File Explorer
How do I get to see the thumbnail preview when using File > Open?
-
Pa40 mail trigger when startdate changed and save,
in pa40 when changing the startdate for corresponding pernr.. after click on save button one mail should be sent to that corresponding pernr mail id. that mail should contain contract extension letter(this i did as zcontract_letter using smar
-
Data Security Standard PCI-DSS - SAP Datacenter
Hello, one of our prospect asked the following question: Does the SAP Datacenter in Germany fullfill the requirements of PCI-DSS? It seems that this Standard is related to the Payment Card Processing. I checked all certifiates but I don´t find any in