Help in getting desired output
I need to generate a report products per month and also running total.Here below i am consolidated my data to one table as below sample.This will going to run for 10 years of data.Can any one suggest the solution for this.
CREATE TABLE test_Prd(
PrdId int ,
PrdSrl varchar(10) ,
PlcyCd char(2) ,
WntyStDate datetime
INSERT INTO test_Prd VALUES (1001,'F1001','QB','03/13/2008');
INSERT INTO test_Prd VALUES (1002,'F1002','QB','01/22/2008');
INSERT INTO test_Prd VALUES (1003,'W1001','QB','02/02/2008');
INSERT INTO test_Prd VALUES (1004,'F1003','SB','05/10/2008');
INSERT INTO test_Prd VALUES (1005,'F1005','SB','04/24/2008');
INSERT INTO test_Prd VALUES (1006,'F1006','QB','02/10/2008');
INSERT INTO test_Prd VALUES (1007,'W1002','QB','03/20/2008');
INSERT INTO test_Prd VALUES (1008,'F1007','QB','04/22/2008');
INSERT INTO test_Prd VALUES (1009,'F1008','QB','06/17/2008');
INSERT INTO test_Prd VALUES (1010,'F1009','SB','08/12/2008');
INSERT INTO test_Prd VALUES (1011,'F10011','SB','03/13/2008');
INSERT INTO test_Prd VALUES (1012,'F10012','SB','01/22/2008');
INSERT INTO test_Prd VALUES (1013,'W10011','QB','02/02/2008');
INSERT INTO test_Prd VALUES (1014,'F10013','QB','05/10/2008');
INSERT INTO test_Prd VALUES (1016,'W10016','QB','02/10/2008');
INSERT INTO test_Prd VALUES (1017,'W10012','QB','05/20/2008');
INSERT INTO test_Prd VALUES (1015,'F10015','QB','04/24/2008');
INSERT INTO test_Prd VALUES (1018,'F10017','SB','04/14/2008');
INSERT INTO test_Prd VALUES (1019,'F10018','QB','06/17/2008');
INSERT INTO test_Prd VALUES (1020,'F10019','QB','08/12/2008');
select substring(prdsrl,1,1) as sprd
,plcycd
,datediff(month,wntystdate,'08/31/2008') as mnth
,count(*) as cnt
from test_Prd
WHERE wntystdate BETWEEN '01/01/2007' AND '08/31/2008'
and datediff(month,wntystdate,'08/31/2008')>0
group by substring(prdsrl,1,1)
,plcycd
,datediff(month,wntystdate,'08/31/2008')
order by 1,2,3
the OUT PUT should look like below
sprd plcycd mnth cnt total
F QB 1 0 8
F QB 2 2 8
F QB 3 1 6
F QB 4 2 5
F QB 5 1 3
F QB 6 1 2
F QB 7 1 1
F SB 1 0 5
F SB 2 0 5
F SB 3 1 5
F SB 4 2 4
F SB 5 1 2
F SB 6 0 1
F SB 7 1 1
W QB 1 0 5
W QB 2 0 5
W QB 3 1 5
W QB 4 0 4
W QB 5 1 4
W QB 6 3 3
Hi,
There must be something simpler, but here's one way to do that in Oracle SQL:
WITH d AS
( -- Begin sub-query d, transformed data
SELECT SUBSTR (prdsrl, 1, 1) AS sprd
, plcycd
, TRUNC ( MONTHS_BETWEEN ( TO_DATE (:end_date, 'MM/DD/YYYY')
, Wntystdate
) AS mnth
FROM test_Prd
WHERE wntystdate BETWEEN TO_DATE (:begin_date, 'MM/DD/YYYY')
AND TO_DATE (:end_date, 'MM/DD/YYYY')
) -- End sub-query d, transformed data
, g AS
( -- Begin sub-query g, GROUP BY
SELECT sprd
, plcycd
, mnth
, COUNT (*) AS cnt
FROM d
WHERE mnth > 0
GROUP BY sprd
, plcycd
, mnth
) -- End sub-query g, GROUP BY
, m AS
( -- Begin sub-query m, all possible months
SELECT ROWNUM AS mnth
FROM ( SELECT MAX (mnth) AS max_mnth
FROM g
CONNECT BY ROWNUM <= max_mnth
) -- End sub-query m, all possible months
, c AS
( -- Begin sub-query c, all combinations of sprd, plcycd and mnth
SELECT DISTINCT
g.sprd
, g.plcycd
, m.mnth
FROM m
CROSS JOIN g
) -- End sub-query c, all combinations of sprd, plcycd and mnth
, t AS
( -- Begin sub-query t, to compute total
SELECT c.*
, NVL (g.cnt, 0) AS cnt
, NVL ( SUM (cnt) OVER
( PARTITION BY c.sprd
, c.plcycd
ORDER BY c.mnth DESC
, 0
) AS total
FROM c
LEFT OUTER JOIN g ON c.sprd = g.sprd
AND c.plcycd = g.plcycd
AND c.mnth = g.mnth
) -- End sub-query t, to compute total
SELECT *
FROM t
WHERE total > 0
ORDER BY sprd
, plcycd
, mnth
;I'm guessing at what the function datedif does.
Similar Messages
-
How to join to column details to get desired output
Kindly refer the attached queries namely
1)REORDER
2)PENDING WORKORDER
I want to calculate the work order requirement on basis of
Stock, Pending sales order, re-order level and already entered workorders. Now i want to add the first column of 2nd query in the report of 1st query. For that i tried the below statements
AND ITEM_CODE = LCS_ITEM_CODE (+)
AND ITEM_CODE = SOI_ITEM_CODE (+)
AND ITEM_CODE = PWH_ITEM_CODE (+)
LCS_ITEM_CODE is Stock table item_code,
SOI_ITEM_CODE is Sales order item_code,
PWH_ITEM_CODE is Production work order item_code,
When the above statments used while combining the 2 queries does display the result, but the details comes only for the ietm_codes whose work orders are present.
Kindly guide me how can i get the desired output.
1)RE-ORDER QUERY :
SELECT DISTINCT ITEM_CODE,
ITEM_NAME,
(CASE
WHEN SUBSTR(ITEM_CODE,11,3) = '000' THEN 'LOOSE'
ELSE SUBSTR(ITEM_CODE,11,4)
END) PKG_SIZE,
((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1) * TO_NUMBER(SUBSTR(ITEM_CODE,- 3,3))
||DECODE(SUBSTR(LCS_ITEM_CODE,11,3),'000',((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1)) STOCK,
(CASE
WHEN SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1)) < 0 THEN 0
ELSE SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1))
END) PNDG,
((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1) * TO_NUMBER(SUBSTR(ITEM_CODE,- 3,3))
||DECODE(SUBSTR(LCS_ITEM_CODE,11,3),'000',((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1)) - SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1)) NETSTK,
ITEM_RORD_LVL REORD_LVL,
(CASE
WHEN ((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1) * TO_NUMBER(SUBSTR(ITEM_CODE,- 3,3))
||DECODE(SUBSTR(LCS_ITEM_CODE,11,3),'000',((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1)) - SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1)) > 0
AND ITEM_RORD_LVL > 0 THEN ((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1) * TO_NUMBER(SUBSTR(ITEM_CODE,- 3,3))
||DECODE(SUBSTR(LCS_ITEM_CODE,11,3),'000',((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1)) - SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1))
ELSE NVL(ITEM_RORD_LVL,0) - (((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1) * TO_NUMBER(SUBSTR(ITEM_CODE,- 3,3))
||DECODE(SUBSTR(LCS_ITEM_CODE,11,3),'000',((LCS_STK_QTY_BU + LCS_RCVD_QTY_BU - LCS_ISSD_QTY_BU) / IU_MAX_LOOSE_1)) - SUM(TO_NUMBER(SOI_QTY
||'.'
||SOI_QTY_LS) - (SOI_INVI_QTY_BU / IU_CONV_FACTOR / IU_MAX_LOOSE_1)))
END) REQ,
DECODE(ITEM_RORD_QTY_LS,NULL,ITEM_RORD_QTY,
(ITEM_RORD_QTY
||'.'
||ITEM_RORD_QTY_LS)) BTCHSZE
FROM OM_ITEM,
OT_SO_HEAD,
OT_SO_ITEM,
OM_ITEM_UOM,
OS_LOCN_CURR_STK
WHERE (ITEM_UOM_CODE = IU_UOM_CODE
AND ITEM_CODE = IU_ITEM_CODE)
AND ITEM_CODE = LCS_ITEM_CODE (+)
AND ITEM_CODE = SOI_ITEM_CODE (+)
AND LCS_LOCN_CODE = 'FG'
AND LCS_ITEM_CODE = SOI_ITEM_CODE
AND SOI_SOH_SYS_ID = SOH_SYS_ID
AND SOH_TXN_CODE IN ('SORLLOC',
'SORLCT3',
'SORLNPL',
'EXPFABLK')
AND NVL(SOH_CLO_STATUS,0) = 0
AND NVL(SOI_SHORT_CLO_STATUS,2) = 2
GROUP BY ITEM_CODE,
ITEM_NAME,
LCS_STK_QTY_BU,
LCS_RCVD_QTY_BU,
LCS_ISSD_QTY_BU,
IU_MAX_LOOSE_1,
ITEM_RORD_LVL_LS,
ITEM_RORD_LVL,
ITEM_RORD_QTY_LS,
ITEM_RORD_QTY,
LCS_ITEM_CODE
ORDER BY ITEM_CODE ASC
2) WORK-ORDERS QUERY :
SELECT DISTINCT PWH_NO PWO_NO,
PWH_DT PWO_DT,
(CASE
WHEN PWFGPI_QTY = 0 THEN PWH_ITEM_CODE
ELSE PWFGPI_ITEM_CODE
END) ITEMCODE,
ITEM_NAME PRODUCT_NAME,
(CASE
WHEN PWFGPI_QTY = 0 THEN SUM(PWH_QTY)
ELSE PWFGPI_QTY * SUBSTR(PWFGPI_ITEM_CODE,11,3)
END) PWO_QTY,
PSD_PR_ACCP_QTY_BU / 1000 PROD_REP,
PWH_PS_QTY_BU / 1000 PROD_SLIP_PENDING
FROM OT_PWO_HEAD,
OM_ITEM,
OT_PWO_STAGE_DETAIL,
OT_PWO_FG_PACKED_ITEM
WHERE PWH_ITEM_CODE = ITEM_CODE
AND PWFGPI_PWH_SYS_ID = PWH_SYS_ID
AND NVL(PWH_CLO_STATUS,0) = 0
AND PSD_PWH_SYS_ID = PWH_SYS_ID
AND PWH_PS_QTY_BU / 1000 IS NULL
GROUP BY PWH_NO,
PWH_DT,
PWH_ITEM_CODE,
ITEM_NAME,
PWFGPI_ITEM_CODE,
PWFGPI_QTY,
PSD_PR_ACCP_QTY_BU,
PWH_PS_QTY_BU,
ITEM_CODE
ORDER BY PWH_NOThat's a big query.
Can I point out that
(CASE
WHEN SUM ( TO_NUMBER (soi_qty || '.' || soi_qty_ls)
- ( soi_invi_qty_bu
/ iu_conv_factor
/ iu_max_loose_1
) < 0
THEN 0
ELSE SUM ( TO_NUMBER (soi_qty || '.' || soi_qty_ls)
- ( soi_invi_qty_bu
/ iu_conv_factor
/ iu_max_loose_1
ENDis just
GREATEST(0, SUM ( TO_NUMBER (soi_qty || '.' || soi_qty_ls)
- ( soi_invi_qty_bu
/ iu_conv_factor
/ iu_max_loose_1
)and
DECODE (item_rord_qty_ls,
NULL, item_rord_qty,
(item_rord_qty || '.' || item_rord_qty_ls
)is just
RTRIM (item_rord_qty || '.' || item_rord_qty_ls,'.') -
declare
v_sys number ;
v_amt number ;
dt date;
cursor c is (select hcode,amt,EDATE,
dense_rank() over(order by hcode)x from a );
begin
v_sys :=1 ;
v_amt :=0 ;
for var in c loop
insert into b values(var.x,var.hcode);
if (v_sys = var.x ) then
v_amt := v_amt + var.amt ;
else
insert into c values(v_sys,v_amt,var.edate );
v_amt := var.amt ;
v_sys := var.x ;
dt:=var.edate;
end if ;
end loop;
insert into c values(v_sys,v_amt,dt );
end;..All is well with this code except it returns the value of table b as:
SQL> select * from b;
ID HCODE
1 10
1 10
2 20
2 20I need to get the output as:
SQL> select * from b;
ID HCODE
1 10
2 20Any idea?
ThanksWell, hcode = 10 and hcode = 20 both appear twice in the cursor you are walking through. The first thing you do after fetching a record is INSERT INTO b. Since there are two records in the cursor for hcode = 10, you get two records in b.
I'm not entirely sure what you are trying to do here, but I suspect that you are rolling you own SUM for some reason. If so, then I think you need something more like:
DECLARE
v_sys NUMBER;
v_amt NUMBER;
dt DATE;
CURSOR c IS
SELECT hcode, amt, edate, DENSE_RANK() OVER(ORDER BY hcode) x
FROM a;
BEGIN
v_sys :=1;
v_amt :=0;
FOR var IN c LOOP
IF (v_sys = var.x ) THEN
v_amt := v_amt + var.amt;
ELSE
INSERT INTO c VALUES (v_sys, v_amt, var.edate);
INSERT INTO b VALUES(var.x, var.hcode);
v_amt := var.amt;
v_sys := var.x;
dt:=var.edate;
END IF;
END LOOP;
INSERT INTO c values(v_sys,v_amt,dt );
END;John -
Problem in query not getting desired output .
i have the following table
mysql> select * from emp;
+------+-------+--------+-------+
| eid | ename | salary | depid |
+------+-------+--------+-------+
| 11 | ram | 5000 | d1 |
| 22 | shyam | 3000 | d1 |
| 23 | mohan | 5500 | d2 |
| 44 | radha | 8000 | d3 |
| 48 | abhi | 10000 | d3 |
+------+-------+--------+-------+
i am executing the following query :
mysql> select depid,count(depid) from emp where salary >5100 group by depid;
and getting following result :
+-------+--------------+
| depid | count(depid) |
+-------+--------------+
| d2 | 1 |
| d3 | 2 |
+-------+--------------+
2 rows in set (0.00 sec)
i wants out put like this :
+-------+--------------+
| depid | count(depid) |
+-------+--------------+
|d1 | 0 |
| d2 | 1 |
| d3 | 2 |
+-------+--------------+
thanks in advance .
csghanny.Hi
csghanny,
You question seems to be wrong.
Because you are providing the filter condition where salary is greater than 5100. and for department d1, there is no salary more than 5100.
+------+-------+--------+-------+
| eid | ename | salary | depid |
+------+-------+--------+-------+
| 11 | ram | 5000 | d1 |
| 22 | shyam | 3000 | d1 |
| 23 | mohan | 5500 | d2 |
| 44 | radha | 8000 | d3 |
| 48 | abhi | 10000 | d3 |
+------+-------+--------+-------+
select depid, count(depid) from emp where salary >5100 group by depid;
so there is no chance that this query will return the output what you are expecting.
let us know, if you requirement is something different, so we can help you.
Please Mark as Answer if my post solved your problem or Vote As Helpful if this helps. Blogs: www.sqlserver2005forum.blogspot.com -
How to execute this Procedure and get the output?
I have created a Procedure the source code of the same is furnished below.
create or replace procedure vin_test( p_deptno IN number
, p_cursor OUT SYS_REFCURSOR)
as
v_res Emp%rowtype;
begin
open p_cursor FOR
select *
from emp
where deptno = p_deptno;
end vin_test;
Now, if i want to see the out put of this Proc
i will first set the Serveroutput on and then..
Exec vin_test(10);
I am getting an error saying wrong number of arguments,so can anybody tell me what parameter value should i pass on so that i can get desired output.
Thanks in Advance
OraCrazyIn sqlplus you can do like this.
SQL> create or replace procedure vin_test( p_deptno IN number, p_cursor OUT SYS_REFCURSOR)
2 as
3 v_res Emp%rowtype;
4 begin
5 open p_cursor for
6 select *
7 from emp
8 where deptno = p_deptno;
9 end;
10 /
Procedure created.
SQL> var lcur refcursor
SQL> exec vin_test(30,:lcur)
PL/SQL procedure successfully completed.
SQL> print lcur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DIV
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 10
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 10
7900 JAMES CLERK 7698 03-DEC-81 950 30 10
6 rows selected.Thanks,
Karthick. -
Help needed in getting formatted output ?
Hi members,
I am a newbie in Java programming. I know C, C++ upto a good level. I was trying to print a pattern like:
1
12
123
1234
12345
But wasn't able to get the output in desired format. I just wanna know how can i get the above mentioned output. The code i written is shown below alongwith the output:
/* This program is used to print the Pattern of 1,12..... */
class pattern
public static void main(String args[])
int i=1,j=1;
while(i<=5)
j=1;
while(j<=i)
System.out.println("\t "+ j);
j++;
i++;
System.out.println("\n");
output:
F:\Jprograms>java pattern
1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
F:\Jprograms>
Any help will be appreciated.
With regards
Real NapsterIt's the statement you're using to print to the console:
println() means print, then go to next line.
print() doesn't go to the next line.
So:
System.out.println("1");
System.out.println("2");
Gives
1
2
But System.out.print("1");
System.out.print("2");
Gives
12 -
Need Help in Getting the below output
Hi All,
The below is the table data.
col1 col2 col3 col4 col5 col6
Aa 1 Con 100 10 -1
Ba 2 Cam 50 2 33
Aa 1 Con 200 20 -2
Ca 3 val 2 5 -10
Aa 1 Con 150 30 -3
Ba 2 Cam 20 3 11
Ca 3 val 3 5 -20
Ba 2 Cam 30 5 22
Ca 3 val 5 4 -30
I need the output as below. Please help me in getting the output.
col1 col2 col3 col4 col5 col6
Aa 1 Con 100 10 -1
Aa 1 Con 200 20 -2
Aa 1 Con 150 30 -3
Aa-Con Subtotal 450 60 -6
Ba 2 Cam 20 3 11
Ba 2 Cam 30 5 22
Ba 2 Cam 50 2 33
Ba-Cam Subtotal 100 10 66
Ca 3 val 2 5 -10
Ca 3 val 3 5 -20
Ca 3 val 5 4 -30
Ca-val Subtotal 10 14 -60
I am using Oracle 10g. Let me know if other details required.
Thanks in Advance.
Regards,
Ravi Kumar Ankarapu.You can try using ROLLUP and GROUPING SETS like how some of the other forum members have suggested. Another way of getting the desired output would be :
with t as
select 'Aa' col1, 1 col2, 'Con' col3, 100 col4, 10 col5, -1 col6 from dual
union all
select 'Ba', 2, 'Cam', 50, 2, 33 from dual
union all
select 'Aa', 1, 'Con', 200, 20, -2 from dual
union all
select 'Ca', 3, 'val', 2, 5, -10 from dual
union all
select 'Aa', 1, 'Con', 150, 30, -3 from dual
union all
select 'Ba', 2, 'Cam', 20, 3, 11 from dual
union all
select 'Ca', 3 ,'val', 3, 5, -20 from dual
union all
select 'Ba', 2, 'Cam', 30, 5, 22 from dual
union all
select 'Ca', 3, 'val', 5, 4, -30 from dual
select * from
select * from t
union all
select distinct * from
select col1 || '-' || col3 || ' Sub-total' col1, null col2, null col3,
sum(col4) over (partition by col1 order by col1) col4,
sum(col5) over (partition by col1 order by col1) col5,
sum(col6) over (partition by col1 order by col1) col6
from t
order by col1, col2, col3
Output:
"COL1" "COL2" "COL3" "COL4" "COL5" "COL6"
"Aa" "1" "Con" "150" "30" "-3"
"Aa" "1" "Con" "100" "10" "-1"
"Aa" "1" "Con" "200" "20" "-2"
"Aa-Con Sub-total" "" "" "450" "60" "-6"
"Ba" "2" "Cam" "50" "2" "33"
"Ba" "2" "Cam" "20" "3" "11"
"Ba" "2" "Cam" "30" "5" "22"
"Ba-Cam Sub-total" "" "" "100" "10" "66"
"Ca" "3" "val" "5" "4" "-30"
"Ca" "3" "val" "2" "5" "-10"
"Ca" "3" "val" "3" "5" "-20"
"Ca-val Sub-total" "" "" "10" "14" "-60" -
How to correctly perform a join to get the desired output
Hi,
I have the following query which gives me the desired output.
SELECT
Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
'Store' As DRIVER_TYPE,
'OPS GOAL' As DRIVER,
SUM(OPS_GOAL) As ROW_TOTAL
FROM Planning.TEDW_F_STORE_OPS_GOAL
left outer join
edw.Calendar.TEDW_D_DATE_TYPE_1
ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
left outer join
[EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
group by
TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
TEDW_D_DATE_TYPE_1.DATE_SHORT
order by LOCATION_NUM desc
, DATE_SHORT desc
The output of the above query will be like this
3646 2014-04-17 Store OPS GOAL 2598.00000
3646 2014-04-16 Store OPS GOAL 2475.00000
3646 2014-04-15 Store OPS GOAL 2497.00000
3646 2014-04-14 Store OPS GOAL 2691.00000
But the problem with this query is it brings back the OPS Goal for all the dates,but i have to limit the OPS goals to some particular date range which must match to this table Staging.TEDW_S_EMPOWER.So,I made the above query join to this table like this
SELECT
Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
'Store' As DRIVER_TYPE,
'OPS GOAL' As DRIVER,
SUM(OPS_GOAL) As ROW_TOTAL
FROM Planning.TEDW_F_STORE_OPS_GOAL
left outer join
edw.Calendar.TEDW_D_DATE_TYPE_1
ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
left outer join
[EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
left outer join
Staging.TEDW_S_EMPOWER
on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
group by
TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
TEDW_D_DATE_TYPE_1.DATE_SHORT
having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
order by LOCATION_NUM desc
, DATE_SHORT desc
Now the output of this query will be like this
3646 2014-04-17 Store OPS GOAL 7794.00000
3646 2014-04-16 Store OPS GOAL 7425.00000
3646 2014-04-15 Store OPS GOAL 7491.00000
3646 2014-04-14 Store OPS GOAL 8073.00000
If you can observe the OPS Goal Sum values have changed drastically, i was able to limit the date range i wanted but now i dont get the correct OPS Goal values.
Can someone please help me with this?
ThanksHi RJP,
Yes you are absolutely correct, in the "Staging.TEDW_S_EMPOWER"
we have 3 rows for every date and location,so i changed my second sql to be something like this
SELECT
Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
'Store' As DRIVER_TYPE,
'OPS GOAL' As DRIVER,
SUM(OPS_GOAL) /3 As ROW_TOTAL
FROM Planning.TEDW_F_STORE_OPS_GOAL
cross join
EDW.Utility.TEDW_J_PROCESS_DATE
inner join
edw.Calendar.TEDW_D_DATE_TYPE_1
ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
left outer join
[EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
left outer join
Staging.TEDW_S_EMPOWER
on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
group by
TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
TEDW_D_DATE_TYPE_1.DATE_SHORT
having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
order by LOCATION_NUM desc
, DATE_SHORT desc
Now i receive the correct values as i am doing divided
by 3,but may be in the future the empower tablemay have more than 3 ,is there any other effective way i can do this?
below is the sample query and sample data from empower table.
select * from Staging.TEDW_S_EMPOWER
where DATE_SHORT = '2014-04-17'
and LOCATION_NUM = 3020
DRIVER_TYPE DRIVER DATE_SHORT
store Sales 2014-04-17
store Transactions 2014-04-17
store Traffic 2014-04-17
Thanks -
NOOB Question - Cannot seem to get the output in a text or CSV file - Please help!!
I was able to put together a script which finds members of a certain AD group, filters down the users, and then calculates the number of days till a password reset is needed. I am able to get on screen exactly what i am looking for, but cannot seem
to figure out how to get the same data to a file. What i am doing wrong? two goals here:
1. Create a spreadsheet with a list of users whose password is about to expire.
2. Down the line automate an email to users whose password is about to expire.
Here is my code:
## Get List Of Users in Password Change Lockout that do not have an expired password or a password that never expires
$Names = (Get-ADGroupMember -Identity "Password Change Lockout" -Recursive |`
Get-ADUser -Properties * |`
Where-Object {$_.PasswordNeverExpires -eq $False -and $_.PasswordExpired -eq $False} |`
Sort-Object name |Select-Object -ExpandProperty SamAccountName)
## Get Password last Set values for all
Foreach ($Name in $Names)
$VAR1 = (Get-ADUserResultantPasswordPolicy -Identity $Name).MaxPasswordAge
$VAR2 = (Get-ADUser $Name -Properties *).passwordlastset
$VAR3 = (Get-ADUser $Name -Properties *).name
$DTPC = (New-TimeSpan -Start (Get-Date) -End ($VAR2 + $VAR1) | Select-Object -ExpandProperty Days)
Filter users to those who need to change thier password in 15 days.
If ($DTPC -lt 15)
No matter what i try between the {} after the If statement, I cannot get the output to a file. However, if I use a Write-Output I get exactly what i looking for. I feel like i am forgetting some basic concept and could really use some help. Thanks.
Matt
Matt DillonHi Matt,
I generally create an empty array (something like $out = @()) at the top of the script and then use $out += $desiredOutput inside of the foreach loop.
Outside of the loop, you can then pipe $out to Out-File or Export-Csv, depending on your needs.
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
How to set Back ground job & get my desired output layout in sm36 & sm37 ?
Hai SAP ABAP/BASIS Gurus,
I am currently taking ME2N PO Pending value Report by setting variant in input screen & setting my own output layout ie only four field ie.Plant, Material,Currency,Still to be delivered value will be visible in output screen
I set Back ground in sm36 using my variant & i saw my output in sm37.. But I cant get output as my desired field..
This is my problem..
1) I Cant Get the Same output in shedule job [sm36 & sm37] like When i run in foreground for ME2n.
I am using ALV Scope of list..
2) If I use BEST Layout in Scope of list means i get the desired Output field layout as same as my foreground output field..
I want to get the output layout as desired & also in ALV format[ Useful for excel work]
Kindly guide me.
Thanks in advance..
swetha
Edited by: Swetha SAP Girl on Jul 2, 2009 5:06 PMHi Swetha,
To get the missed fields in the spool, while creating the background job(execute in background option) you can see the printer setting block at the end of the background job settings window, in that check the 'Spool Request Max. Width 255 char' check box and then continue. It will generate the spool list with maximum width and you can see all the fields in the spool output.
Thanks,
Muthu
Edited by: Muthu Prabakaran Selvam on Jul 3, 2009 2:35 PM -
Help me to get the output !
REPORT ZTEST9 LINE-SIZE 800.
TABLES: VBAP.
DATA: BEGIN OF I_VBAP OCCURS 0,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
MATWA TYPE VBAP-MATWA,
PMATN TYPE VBAP-PMATN,
CHARG TYPE VBAP-CHARG,
MATKL TYPE VBAP-MATKL,
ARKTX TYPE VBAP-ARKTX,
PSTYV TYPE VBAP-PSTYV,
END OF I_VBAP.
BREAK-POINT.
SELECT * FROM VBAP INTO CORRESPONDING FIELDS OF TABLE I_VBAP
WHERE VBAP~VBELN EQ '60002744'.
LOOP AT I_VBAP.
WRITE :/
I_VBAP-VBELN,
I_VBAP-POSNR,
I_VBAP-MATNR,
I_VBAP-MATWA,
I_VBAP-PMATN,
I_VBAP-CHARG,
I_VBAP-MATKL,
I_VBAP-ARKTX,
I_VBAP-PSTYV.
ENDLOOP.
I AM NOT GETTING ANY OUTPUT WHEN I USE 'EQ' OPERATOR. BUT ITS WORKING FINE WHEN I AM USING PARAMETES : ..
PLEASE HELPhi nirajana ,
DATA: BEGIN OF i_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
matwa TYPE vbap-matwa,
pmatn TYPE vbap-pmatn,
charg TYPE vbap-charg,
matkl TYPE vbap-matkl,
arktx TYPE vbap-arktx,
pstyv TYPE vbap-pstyv,
END OF i_vbap.
DATA: t_vbap LIKE STANDARD TABLE OF i_vbap.
SELECT vbeln
posnr
matnr
matwa
pmatn
charg
matkl
arktx
pstyv
FROM vbap INTO TABLE t_vbap
WHERE vbeln EQ '6000274'.
LOOP AT t_vbap INTO i_vbap .
WRITE :/
i_vbap-vbeln,
i_vbap-posnr,
i_vbap-matnr,
i_vbap-matwa,
i_vbap-pmatn,
i_vbap-charg,
i_vbap-matkl,
i_vbap-arktx,
i_vbap-pstyv.
ENDLOOP.
do like this .
for particular vbeln entry . no data is present in the table .
regards ,
sandeep patel
award point if it is helpful. -
I am not getting any output from the speakers of the ipad. However the sound is ok if i use headphones. Can anyone help?
1. Check the Side Switch
http://i1224.photobucket.com/albums/ee374/Diavonex/00bf6eae.jpg
2. Double-click the Home button and swipe to the right and check volume control
http://i1224.photobucket.com/albums/ee374/Diavonex/ea5b842d.jpg
3. Settings>Notification>Game Center>Sound>ON
http://i1224.photobucket.com/albums/ee374/Diavonex/67a15edf.jpg -
How to get the desire output from sql query
Consider an Order Table: ...
Order Table:
Order Id Item Qty
O1 A1 5
O2 A2 1
O3 A3 3
Please provide SQL which will explode the above data into single unit level records as shown below
Desired Output:
Order Id Order Id Qty
O1 A1 1
O1 A1 1
O1 A1 1
O1 A1 1
O1 A1 1
O2 A2 1
O3 A3 1
O3 A3 1
O3 A3 1How do I ask a question on the forums?
SQL and PL/SQL FAQ -
Format-number,decimal not giving desired output for PO Print report XSL-FO
Hi All,
My requirement was to get the Unit price in european format which is 10.000,00
Iam getting it as 10000,00 but the client needs the thousand's seperator.
if have used the decimal seperator but iam getting the Unit Price value as 'NAN' when i submit it for an international language like Italian or Spanish
This is what i have done
set the decimal format
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
<xsl:value-of select="format-number(UNIT_PRICE, '#.###,####', 'euro')"/>
This gives the desired output when i select the US language.
While submitting through the conc request
If i change the Numeric char to '.,' by clickin on Language settings..It works great
I have tried to use the replace function but the syntax is not correct
format-number(replace('UNIT_PRICE',',','.'), '#.###.###.###,####', 'euro')
Any Help would be greatly appreciated.
Thanks
MirzaHi Mirza,
I'm struggling having the same problem. Have you found any solution?
Best regards
Kenneth -
How to modify the query to get the output in a single row
Hi All,
Below is the query i have written it works fine
select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
tODS_GLBalance.FiscalYearId AS FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
--tods_GLMetadata.Metric,
Case when
tods_GLMetadata.Metric = 'Gross Margin'
Then SUM(Balance)
Else 0
END AS GrossMargin,
Case when
tods_GLMetadata.Metric = 'Occupancy'
Then SUM(Balance)
Else 0
END AS Occupancy,
Case when
tods_GLMetadata.Metric = 'Payroll Dollars'
Then SUM(Balance)
Else 0
END AS Payroll,
Case when
tods_GLMetadata.Metric = 'CF Sales'
Then SUM(Balance)
Else 0
END AS OperatingSales,
Case when
tods_GLMetadata.Metric = 'Operations'
Then SUM(Balance)
Else 0
END AS OperatingExpenses
-- 0 as payroll
from ods.[JJill].[tODS_GLBalance]
inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
where
(tODS_GLBalance.FiscalYearId = 2012) and
(tODS_GLBalance.FiscalMonthOfYearId = 2) and
(right(left(CTACCT,13),4)= 3020)
group by
right(left(CTACCT,13),4),
tODS_GLBalance.FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId,
tods_GLMetadata.Metric
This is the sample output,
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
3020 2012 2 0.00 0.00 0.00 0.00 5625.44
3020 2012 2 0.00 0.00 24185.79 0.00 0.00
3020 2012 2 0.00 31075.53 0.00 0.00 0.00
But, i am expecting the output to be something like this
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
Can someone please help me with changing my query to get the desired output?
Please let me know if you have any questions.
ThanksTry this:
SELECT DISTINCT
RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
FROM ods.[JJill].[tODS_GLBalance]
INNER JOIN ods.Staging.tODS_INF_GLPCT
ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
INNER JOIN ods.JJill.tods_GLMetadata
ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
WHERE tODS_GLBalance.FiscalYearId = 2012
AND tODS_GLBalance.FiscalMonthOfYearId = 2
AND RIGHT(LEFT(CTACCT,13),4) = 3020
GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric
Maybe you are looking for
-
How do I transfer my Itunes Library onto a new computer?
I feel pretty silly, but I just got a new laptop and want to transfer the music I have purchased. Do I upload from my Ipod? Or do I burn the library off the old computer and upload on the new one. The old operating system was Windows XP, the new one
-
How to control the alternative payee from invoice postings
hi, i have a requirement, we are useing the alternative payee for vandor payment, my client want to post only payments through alternative payee. some times by mistake users posted invoices to alternative payee account. so here after i want to contr
-
How to create a new client in SAP?
Hi Experts, In my SAP system client 800 is already exists.And I want to practice ALE I need another client.So can exactly tell me steps to create new client?
-
I installed JBI sdk. There is a examples directory. But the examples it offered are not a java-based program. I couldn't find any java files under it and I didn't know how to use the jbi api. All of them are made by XML file. Where can I find a java-
-
Hi All, One of my SQL Server 2005(SP4) Update statistics maintenance plan is failing some days with the below reason. The process cannot access the file 'C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\LOG\\MaintenancePlan_UPDATE STATS_2014