How to write formulas based on text of columns in another table
We have thousands of formulas stored in a table 'Formulas'. How can we calculate values from a data table 'D1' based on the formulas in 'Formulas'
Table 'D1' has columns:
V1 V2 V3 V4 V5
with standard numeric data.
Table 'Formulas' has columns Date and F1 with value such as
Date F1
2013 'v1=v2+v3'
2014 'v1=v2*v5'
The formulas in 'Formulas' are date-specific and also can change over time, so the solution must be dynamically generated during execution.
Thanks!
If the table is relatively small, you may try:
IF object_id(N'TempDB..#D1') IS NOT NULL
DROP TABLE #D1;
CREATE TABLE #D1 (
Id INT identity(1, 1) PRIMARY KEY
,v1 DECIMAL(10, 2)
,v2 DECIMAL(10, 2)
,v3 DECIMAL(10, 2)
,v4 DECIMAL(10, 2)
,v5 DECIMAL(10, 2)
,formula VARCHAR(200)
INSERT INTO #D1 (
v1
,v2
,v3
,v4
,v5
,formula
VALUES (
10
,12
,14
,8
,3
,'v1=v2+v3'
7
,5
,3
,9
,4
,'v5=v1*v2'
DECLARE @sql NVARCHAR(max)
SET @sql = stuff((
SELECT ' UNION ALL
SELECT Id, ' + quotename(formula, '''') + ' AS Formula, ' + CASE left(formula, 3)
WHEN 'v1='
THEN substring(formula, 4, len(formula))
ELSE cast(v1 AS VARCHAR(30))
END + ' AS v1,' + CASE left(formula, 3)
WHEN 'v2='
THEN substring(formula, 4, len(formula))
ELSE cast(v2 AS VARCHAR(30))
END + ' AS v2,' + CASE left(formula, 3)
WHEN 'v3='
THEN substring(formula, 4, len(formula))
ELSE cast(v3 AS VARCHAR(30))
END + ' AS v3,' + CASE left(formula, 3)
WHEN 'v4='
THEN substring(formula, 4, len(formula))
ELSE cast(v4 AS VARCHAR(30))
END + ' AS v4,' + CASE left(formula, 3)
WHEN 'v5='
THEN substring(formula, 4, len(formula))
ELSE cast(v5 AS VARCHAR(30))
END + ' AS v5
FROM #D1 WHERE ID =' + cast(Id AS VARCHAR(30))
FROM #D1
FOR XML PATH('')
,TYPE
).value('.', 'varchar(max)'), 1, 12, '')
PRINT @SQL
EXECUTE (@SQL)
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Similar Messages
-
How to create Formula based value field in COPA
Hi,
I want to know how to create formula based value field in COPA
My Requirement is i want to collect some value in formula based value field and want to use in copa allocation cycle as a tracing
factor.
anybody give some light on the same topic or requirement ?
Thanks
Nilesh RThe key figure you are creating in KE2K is not a value field, i.e. you can't post to it and you can't use it in a report. It is a caluculated value that can be used only in assessment and top-down-distribution.
In Ke2K, enter a name for your key figure, then click on the the white sheet button to create it. Now the formular area is open for input. Input your formular (e.g. VV001 + VV002 - VV003 .... where VVXXX are the technical names of value fields).
Now click the "check formuar"-button. Then save.
Before you can use the key figure in assessment, execute TC KEUG.
Now the key figure is available as any value field in the tracing factor selection of your assessment cycle.
I hope this made it clearer.
Regards
Nikolas -
How to populate a table based on a row selection from another table.
Hi, i just started to use ADF BC and Faces. Could some one help me or point me a solution on the following scenario .
By using a search component , a table is being displayed as a search result. If i select any row in the resulted table , i need to populate an another table at the bottom of the same page from another view. These two tables are related by primary key . May i know how to populate a table based on a row selection from another table. Thanks
ganeshI understand your requirement and the tutorial doesn't talk about Association between the views so that you can create a Master-Detail or in DB parlance, a Parent-Child relationship.
I will assume that we are dealing with two entities here: Department and Employees where a particular Department has many Employees and hence a Parent-Child relationship.
Firstly, you need to create an Association between the two Entities - Department and Employees. You can do that by right clicking on the model's entity and then associating the two entities with the appropriate key say, DepartmentId.
Once you have done that, you need to link the two entities in the View section with this Association that you created. Then go to AppModule and make sure that in the Available View Objects: 'EmployeesView' appears under 'DepartmentView' as "EmployeesView via <link you created>". Shuttle the 'DepartmentView' to the right, Data Model and then shuttle
"EmployeesView via <link you created>" to the right, Data Model under 'DepartmentView'.
This will then be reflected in your Data Controls. After that, you simply would have to drag this View into your page as a Master-Detail form...and then when you run this page, any row selected in the Master table, would display the data in the Detail table.
Also, refer to this link: [Master-Detail|http://baigsorcl.blogspot.com/2010/03/creating-master-detail-form-in-adf.html]
Hope this helps. -
How to write export dump commad with no datable data only table structure.
How to write export dump commad with no datable data only table structure will there and command for hole schma.
e.g. export dump command for scott schema and all table within scott schema in it no table data should be exported.If I understand the question, it sounds like you just need to add the flag "ROWS=N" to your export command (I assume that you're talking about the old export utility, not the Data Pump version).
Justin -
How can we modify the maximum no. of columns in pivot table ?
hi all,
How can we modify the maximum no. of columns in pivot table ?
do i need to change the nqconfig.ini or instanceconfig file or else?
thnx..A little search on the forum :
In the instanceconfig.xml add a <PivotView> element under <ServerInstance> if one does
not exist already.
Within the <PivotView> element add an entry that looks like:
<MaxCells>nnnnnn</MaxCells>
where nnnnnn is your desired limit for the maximum total number of cells allowed
in a pivot.
Warning: an excessively large number will cause more memory consumption and
slower browser performance.The details here :
Oracle BI EE (10.1.3.2): Maximum total number of cells in Pivot Table excee -
How to find index name with primarykey and column on a table?
Hi,
how to find index name with primarykey and column on a table?
please help me.
Thankyou.1 select ac.table_name, ac.index_name, aic.column_name
2 from user_constraints ac, user_ind_columns aic
3 where ac.constraint_type = 'P'
4 and ac.index_name = aic.index_name
5* order by 1,2,3
SQL> /
TABLE_NAME INDEX_NAME COLUMN_NAME
ACTION_TABLE SYS_C0011033 NESTED_TABLE_ID
ACTION_TABLE SYS_C0011033 SYS_NC_ARRAY_INDEX$
CATEGORIES_TAB SYS_C0011038 CATEGORY_ID
CUSTOMERS CUSTOMERS_PK CUSTOMER_ID
INVENTORIES INVENTORY_IX PRODUCT_ID
INVENTORIES INVENTORY_IX WAREHOUSE_ID
LINEITEM_TABLE SYS_C0011034 NESTED_TABLE_ID
LINEITEM_TABLE SYS_C0011034 SYS_NC_ARRAY_INDEX$
ORDERS ORDER_PK ORDER_ID
ORDER_ITEMS ORDER_ITEMS_PK LINE_ITEM_ID
ORDER_ITEMS ORDER_ITEMS_PK ORDER_ID
PRODUCT_DESCRIPTIONS PRD_DESC_PK LANGUAGE_ID
PRODUCT_DESCRIPTIONS PRD_DESC_PK PRODUCT_ID
PRODUCT_INFORMATION PRODUCT_INFORMATION_PK PRODUCT_ID
PROMOTIONS PROMO_ID_PK PROMO_ID
WAREHOUSES WAREHOUSES_PK WAREHOUSE_ID
16 rows selected. -
How to write formula for 0calweek from 0calmonth
Hi Friends,
I'm doing weekly report. my infocube, data coming from three sources, two sources are ODS. In ODS doesn't have 0calweek only have 0calmonth. When i see my report i can't view those ODS data in the report.
So i want write a formula. How do i write a formula for this.Pls give me the formula.
Thanks & Regards
SiriI got the solution by creating calweek formula based on Syster date.
Siri -
How to write empty line in text file
hey
i want to insert one empty line in text file.
how to write this.
i declared
data: emptyrec(240) type c value space,
and used
TRANSFER emptyrec to e_file.
but its not inserting empty line in the record.
is there any special way have to do.
ambichan.hai anand,
I am posting the code snippet.
i have commented that transfer line in '----
' like this
pls refer below.
ambichan
DATA: PAGENO(4) TYPE N VALUE 1,
DATAKBN(2) TYPE N VALUE 1,
SUBNO(3) TYPE N VALUE 1,
VPAGENO(4) TYPE C,
VDATAKBN(2) TYPE C,
VSUBNO(3) TYPE C,
VREC(255) TYPE C,
VRECORD(255) TYPE C,
EMPTYREC(255) TYPE C VALUE SPACE,
VCODE(10) TYPE C,
VNAME2(35) TYPE C,
VPAYDAT(10) TYPE C,
VSGTXT(60) TYPE C VALUE SPACE,
VSGTXT1(10) TYPE C,
VKINGAKU(15) TYPE C VALUE SPACE,
VBIKKO(30) TYPE C VALUE SPACE,
VBELNR(10) TYPE C VALUE SPACE,
VDMBTR(15) TYPE C,
VGLT0-KSLVT(15) TYPE C,
VGLT0-TSL01(15) TYPE C,
VGLT0-TSL02(15) TYPE C,
VGLT0-TSL03(15) TYPE C,
VGLT0-TSL04(15) TYPE C,
VGLT0-TSL05(15) TYPE C,
VKIN(15) TYPE C,
VTEGA(15) TYPE C.
FORM FRM_OUTPUT_DATA.
SORT ITAB_OUTPUT_SUMMARY BY LIFNR DTYPE.
SORT ITAB_OUTPUT_ITEMS BY LIFNR DTYPE BELNR.
IF P_DISP = 'X'."checkボクスを選ぶ場合、ファイル作成処理へ行く
OPEN DATASET E_FILE FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC <> 0.
WRITE: 'error',SY-SUBRC.
EXIT.
ENDIF.
LOOP AT ITAB_LIFNR.
PERFORM LISTDATA.
PAGENO = PAGENO + 1.
SUBNO = 1.
ENDLOOP.
CLOSE DATASET E_FILE."ファイルクローズ
ENDFORM. " End of frm_output_data
FORM LISTDATA.
DATA:
WK_PAY_AMOUNT LIKE BSEG-DMBTR, " 純支払額算出用
VWK_PAY_AMOUNT(15) TYPE C,
GLT0-TSL05_VAL LIKE GLT0-TSL05.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 1.
BSIK-DMBTR = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
GLT0-TSL01 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 2. " 区分:2
GLT0-TSL02 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 3. " 区分:3
GLT0-TSL03 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 4. " 区分:4
GLT0-TSL04 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 5. " 区分:5
GLT0-TSL05 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
glt0-tsl05 = glt0-tsl05 + glt0-tsl04.
WK_PAY_AMOUNT = GLT0-TSL05 + GLT0-TSL04.
CHECK WK_SUBRC = 0.
BSEG-KOART = ' '. 情報不要
CLEAR: BSEG-SGTXT, BSEG-DMBTR, TGSBT-GTEXT, BKPF-BELNR.
BSEG-KOART = 'Y'. " フラグ:ヘッダに相殺額を出力
CLEAR: BSAK-DMBTR.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 6. " 区分:6
BSAK-DMBTR = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
WK_PAY_AMOUNT = WK_PAY_AMOUNT - BSAK-DMBTR.
WRITE : / PAGENO,
SUBNO,
DATAKBN,
ITAB_LIFNR-LIFNR,
ITAB_LIFNR-NAME2(25),
P_PAY_T,
GLT0-TSL01,
GLT0-TSL02,
GLT0-TSL03,
GLT0-TSL04,
GLT0-TSL05.
VPAGENO = PAGENO.
VSUBNO = SUBNO.
DATAKBN = 1.
VDATAKBN = DATAKBN.
VCODE = ITAB_LIFNR-LIFNR.
VNAME2 = ITAB_LIFNR-NAME2.
VPAYDAT = P_PAY_T.
VGLT0-TSL01 = GLT0-TSL01.
VGLT0-TSL02 = GLT0-TSL02.
VGLT0-TSL03 = GLT0-TSL03.
VGLT0-TSL04 = GLT0-TSL04.
VGLT0-TSL05 = GLT0-TSL05.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT VKINGAKU
VBIKKO VBELNR VGLT0-TSL01 VGLT0-TSL02 VGLT0-TSL03
VGLT0-TSL04 VGLT0-TSL05 INTO VREC SEPARATED BY ','.
CLEAR: BSAK-DMBTR, BSID-DMBTR, BSAD-DMBTR, BSEG-DMBTR, BSIK-DMBTR,
WK_10 , WK_11 , GLT0-TSL05.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 7. " 区分:7
BSID-DMBTR = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
WK_PAY_AMOUNT = WK_PAY_AMOUNT - BSID-DMBTR.
郵送料の出力処理
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 8. " 区分:8
BSAD-DMBTR = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
WK_PAY_AMOUNT = WK_PAY_AMOUNT - BSAD-DMBTR.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 9. " 区分:9
BSEG-DMBTR = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
WK_PAY_AMOUNT = WK_PAY_AMOUNT - BSEG-DMBTR.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 10.
WK_10 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
READ TABLE ITAB_OUTPUT_SUMMARY
WITH KEY LIFNR = ITAB_LIFNR-LIFNR DTYPE = 11.
WK_11 = ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
GLT0-TSL05 = WK_PAY_AMOUNT - WK_10 - WK_11.
WK_PAY_AMOUNT = WK_PAY_AMOUNT - GLT0-TSL05.
VWK_PAY_AMOUNT = WK_PAY_AMOUNT.
VKIN = WK_10.
VTEGA = WK_11.
CONCATENATE VREC VWK_PAY_AMOUNT VKIN VTEGA INTO
VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
WRITE :
VWK_PAY_AMOUNT,
WK_10,
WK_11.
WRITE:/.
BSEG-KOART = 'X'. " フラグ:請求金額を出力
LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
AND DTYPE = 5. " 区分:5
BSEG-SGTXT = ITAB_OUTPUT_ITEMS-SGTXT. " 明細テキスト
GLT0-KSLVT = ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO. " 金額
TGSBT-GTEXT = ITAB_OUTPUT_ITEMS-GTEXT. BKPF-BELNR = ITAB_OUTPUT_ITEMS-BELNR.
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
DATAKBN = 2.
VDATAKBN = DATAKBN.
VGLT0-KSLVT = GLT0-KSLVT.
VBIKKO = TGSBT-GTEXT.
VBELNR = BKPF-BELNR.
VSGTXT1 ='請求金額:'.
CLEAR VRECORD.
CONCATENATE VSGTXT1 BSEG-SGTXT INTO VSGTXT.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
WRITE :/ VPAGENO,VSUBNO,VDATAKBN,'請求金額:', VSGTXT, VGLT0-KSLVT,
VBIKKO,VBELNR.
ENDLOOP.
CLEAR: BSEG-SGTXT,GLT0-KSLVT,BKPF-BELNR.
LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
AND DTYPE = 6. " 区分:6
BSEG-SGTXT = ITAB_OUTPUT_ITEMS-SGTXT. " 明細テキスト
IF ITAB_OUTPUT_ITEMS-SHKZG = CNS_CREDIT. " 金額
GLT0-KSLVT = ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO.
ELSEIF ITAB_OUTPUT_ITEMS-SHKZG = CNS_DEBIT.
GLT0-KSLVT = ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO * -1.
ENDIF.
TGSBT-GTEXT = ITAB_OUTPUT_ITEMS-GTEXT. " 事業領域テキスト
BKPF-BELNR = ITAB_OUTPUT_ITEMS-BELNR. " 伝票番号
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
DATAKBN = 3.
VDATAKBN = DATAKBN.
VGLT0-KSLVT = GLT0-KSLVT.
VBIKKO = TGSBT-GTEXT.
VBELNR = BKPF-BELNR.
VSGTXT1 ='相殺金額:'.
CLEAR VRECORD.
CONCATENATE VSGTXT1 BSEG-SGTXT INTO VSGTXT.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
concatenate vpageno vsubno vdatakbn
WRITE :/ PAGENO,SUBNO,DATAKBN,'相殺金額',BSEG-SGTXT, GLT0-KSLVT,
TGSBT-GTEXT, BKPF-BELNR.
ENDLOOP.
CLEAR VRECORD.
*Insert empty line.
TRANSFER EMPTYREC TO E_FILE.
DATAKBN = 3.
VDATAKBN = DATAKBN.
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
VSGTXT ='源泉金額'.
VDMBTR = BSID-DMBTR.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VDMBTR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
WRITE :/ PAGENO, SUBNO,DATAKBN, ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
P_PAY_T,'源泉金額', BSID-DMBTR.
CLEAR: VDMBTR, VSGTXT, VRECORD.
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
VSGTXT = '郵送料'.
VDMBTR = BSAD-DMBTR.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VDMBTR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
WRITE :/ PAGENO, SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
P_PAY_T,'郵送料', BSAD-DMBTR.
CLEAR: VDMBTR, VSGTXT, VRECORD.
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
VSGTXT = '振込み手数料'.
VDMBTR = BSEG-DMBTR.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VDMBTR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
CLEAR: VDMBTR, VSGTXT, VRECORD.
WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
P_PAY_T,'振込み手数料',BSEG-DMBTR.
*その他の支払いの処理
SUBNO = SUBNO + 1.
VSUBNO = SUBNO.
VSGTXT = 'その他の支払い'.
VDMBTR = GLT0-TSL05.
CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
VDMBTR INTO VRECORD SEPARATED BY ','.
TRANSFER VRECORD TO E_FILE.
WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
P_PAY_T, 'その他の支払い',GLT0-TSL05.
glt0-tsl05.
ULINE.
CLEAR: VREC, VRECORD,VCODE,VNAME2,VPAYDAT,VSGTXT,VSGTXT1,VKINGAKU.
CLEAR: VBIKKO,VBELNR,VDMBTR,VGLT0-KSLVT,VGLT0-TSL01,VGLT0-TSL02.
CLEAR: VGLT0-TSL03,VGLT0-TSL04,VGLT0-TSL05,VKIN,VTEGA,VWK_PAY_AMOUNT.
ENDFORM. -
Hi,
Iam new to the xml,
can u please anyone help me how to write procedure to load the data into a table using xml as input parameter to a procedure and xml file is as shown below which is input to me.
<?xml version="1.0"?>
<DiseaseCodes>
<Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
<Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
<Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
</DiseaseCodes>.
Regards,
vikram.here is the your XML parse in 11g :
select *
from xmltable('//Entity' passing xmltype
'<?xml version="1.0"?>
<DiseaseCodes>
<Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
<Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
<Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
</DiseaseCodes>
') columns
"dcode" varchar2(4000) path '/Entity/dcode',
"ddesc" varchar2(4000) path '/Entity/ddesc',
"reauthflag" varchar2(4000) path '/Entity/reauthflag'
dcode ddesc reauthflag
0 (I87)Other disorders of veins - postphlebitic syndrome 0
0 (J04)Acute laryngitis and tracheitis 0
0 (J17*)Pneumonia in other diseases - whooping cough 0
SQL>
Using this parser you can create procedure as
SQL> create or replace procedure myXMLParse(x clob) as
2 begin
3 insert into MyXmlTable
4 select *
5 from xmltable('//Entity' passing xmltype(x) columns "dcode"
6 varchar2(4000) path '/Entity/dcode',
7 "ddesc" varchar2(4000) path '/Entity/ddesc',
8 "reauthflag" varchar2(4000) path '/Entity/reauthflag');
9 commit;
10 end;
11
12 /
Procedure created
SQL>
SQL>
SQL> exec myXMLParse('<?xml version="1.0"?><DiseaseCodes><Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity></DiseaseCodes>');
PL/SQL procedure successfully completed
SQL> select * from MYXMLTABLE;
dcode ddesc reauthflag
0 (I87)Other disorders of veins - postphlebitic syndrome 0
0 (J04)Acute laryngitis and tracheitis 0
0 (J17*)Pneumonia in other diseases - whooping cough 0
SQL>
SQL>
Ramin Hashimzade -
How to load DataBlock based on the Multiple Condition from another block
Hi
How to load a Data Block based on the Multiple values from another block. For eg.EMP is the Master Data block and SAL is the child Datablock.When query JOS% in the Master Block(EMP) then display all the Sal details in the SAL block for all the employees starting with JOS , When clicking one buton or if it is possible in the loadin of the MasterBlockHi,
I presume you are using database block relations.
Put automatic query = yes in relation properties.
Do you have block level trigger ON-POPULATE-DETAILS?
In that you can find the relation and query - Using built-ins
Find_Relation and Query_Master_Details -
How to write a cursor to check every row of a table which has millions of rows
Hello every one.
I need help. please... Below is the script (sample data), You can run directly on sql server management studio.
Here we need to update PPTA_Status column in Donation table. There WILL BE 3 statuses, A1, A2 and Q.
Here we need to update PPTA_status of January month donations only. We need to write a cursor. Here as this is a sample data we have only some donations (rows), but in the real table we have millions of rows. Need to check every row.
If i run the cursor for January, cursor should take every row, row by row all the rows of January.
we have donations in don_sample table, i need to check the test_results in the result_sample table for that donations and needs to update PPTA_status COLUMN.
We need to check all the donations of January month one by one. For every donation, we need to check for the 2 previous donations. For the previous donations, we need to in the following way. check
If we want to find previous donations of a donation, first look for the donor of that donation, then we can find previous donations of that donor. Like this we need to check for 2 previous donations.
If there are 2 previous donations and if they have test results, we need to update PPTA_STATUS column of this donatioh as 'Q'.
If 2 previous donation_numbers has test_code column in result_sample table as (9,10,11) values, then it means those donations has result.
BWX72 donor in the sample data I gave is example of above scenario
For the donation we are checking, if it has only 1 previous donation and it has a result in result_sample table, then set this donation Status as A2, after checking the result of this donation also.
ZBW24 donor in the sample data I gave is example of above scenario
For the donation we are checking, if it has only 1 previous donation and it DO NOT have a result in result_sample table, then set this donation Status as A1. after checking the result of this donation also.
PGH56 donor in the sample data I gave is example of above scenario
like this we need to check all the donations in don_sample table, it has millions of rows per every month.
we need to join don_sample and result_sample by donation_number. And we need to check for test_code column for result.
-- creating table
CREATE TABLE [dbo].[DON_SAMPLE](
[donation_number] [varchar](15) NOT NULL,
[donation_date] [datetime] NULL,
[donor_number] [varchar](12) NULL,
[ppta_status] [varchar](5) NULL,
[first_time_donation] [bit] NULL,
[days_since_last_donation] [int] NULL
) ON [PRIMARY]
--inserting values
Insert into [dbo].[DON_SAMPLE] ([donation_number],[donation_date],[donor_number],[ppta_status],[first_time_donation],[days_since_last_donation])
Select '27567167','2013-12-11 00:00:00.000','BWX72','A',1,0
Union ALL
Select '36543897','2014-12-26 00:00:00.000','BWX72','A',0,32
Union ALL
Select '47536542','2014-01-07 00:00:00.000','BWX72','A',0,120
Union ALL
Select '54312654','2014-12-09 00:00:00.000','JPZ41','A',1,0
Union ALL
Select '73276321','2014-12-17 00:00:00.000','JPZ41','A',0,64
Union ALL
Select '83642176','2014-01-15 00:00:00.000','JPZ41','A',0,45
Union ALL
Select '94527541','2014-12-11 00:00:00.000','ZBW24','A',0,120
Union ALL
Select '63497874','2014-01-13 00:00:00.000','ZBW24','A',1,0
Union ALL
Select '95786348','2014-12-17 00:00:00.000','PGH56','A',1,0
Union ALL
Select '87234156','2014-01-27 00:00:00.000','PGH56','A',1,0
--- creating table
CREATE TABLE [dbo].[RESULT_SAMPLE](
[test_result_id] [int] IDENTITY(1,1) NOT NULL,
[donation_number] [varchar](15) NOT NULL,
[donation_date] [datetime] NULL,
[test_code] [varchar](5) NULL,
[test_result_date] [datetime] NULL,
[test_result] [varchar](50) NULL,
[donor_number] [varchar](12) NULL
) ON [PRIMARY]
---SET IDENTITY_INSERT dbo.[RESULT_SAMPLE] ON
---- inserting values
Insert into [dbo].RESULT_SAMPLE( [test_result_id], [donation_number], [donation_date], [test_code], [test_result_date], [test_result], [donor_number])
Select 278453,'27567167','2013-12-11 00:00:00.000','0009','2014-01-20 00:00:00.000','N','BWX72'
Union ALL
Select 278454,'27567167','2013-12-11 00:00:00.000','0010','2014-01-20 00:00:00.000','NEG','BWX72'
Union ALL
Select 278455,'27567167','2013-12-11 00:00:00.000','0011','2014-01-20 00:00:00.000','N','BWX72'
Union ALL
Select 387653,'36543897','2014-12-26 00:00:00.000','0009','2014-01-24 00:00:00.000','N','BWX72'
Union ALL
Select 387654,'36543897','2014-12-26 00:00:00.000','0081','2014-01-24 00:00:00.000','NEG','BWX72'
Union ALL
Select 387655,'36543897','2014-12-26 00:00:00.000','0082','2014-01-24 00:00:00.000','N','BWX72'
UNION ALL
Select 378245,'73276321','2014-12-17 00:00:00.000','0009','2014-01-30 00:00:00.000','N','JPZ41'
Union ALL
Select 378246,'73276321','2014-12-17 00:00:00.000','0010','2014-01-30 00:00:00.000','NEG','JPZ41'
Union ALL
Select 378247,'73276321','2014-12-17 00:00:00.000','0011','2014-01-30 00:00:00.000','NEG','JPZ41'
UNION ALL
Select 561234,'83642176','2014-01-15 00:00:00.000','0081','2014-01-19 00:00:00.000','N','JPZ41'
Union ALL
Select 561235,'83642176','2014-01-15 00:00:00.000','0082','2014-01-19 00:00:00.000','NEG','JPZ41'
Union ALL
Select 561236,'83642176','2014-01-15 00:00:00.000','0083','2014-01-19 00:00:00.000','NEG','JPZ41'
Union ALL
Select 457834,'94527541','2014-12-11 00:00:00.000','0009','2014-01-30 00:00:00.000','N','ZBW24'
Union ALL
Select 457835,'94527541','2014-12-11 00:00:00.000','0010','2014-01-30 00:00:00.000','NEG','ZBW24'
Union ALL
Select 457836,'94527541','2014-12-11 00:00:00.000','0011','2014-01-30 00:00:00.000','NEG','ZBW24'
Union ALL
Select 587345,'63497874','2014-01-13 00:00:00.000','0009','2014-01-29 00:00:00.000','N','ZBW24'
Union ALL
Select 587346,'63497874','2014-01-13 00:00:00.000','0010','2014-01-29 00:00:00.000','NEG','ZBW24'
Union ALL
Select 587347,'63497874','2014-01-13 00:00:00.000','0011','2014-01-29 00:00:00.000','NEG','ZBW24'
Union ALL
Select 524876,'87234156','2014-01-27 00:00:00.000','0081','2014-02-03 00:00:00.000','N','PGH56'
Union ALL
Select 524877,'87234156','2014-01-27 00:00:00.000','0082','2014-02-03 00:00:00.000','N','PGH56'
Union ALL
Select 524878,'87234156','2014-01-27 00:00:00.000','0083','2014-02-03 00:00:00.000','N','PGH56'
select * from DON_SAMPLE
order by donor_number
select * from RESULT_SAMPLE
order by donor_numberYou didn't mention the version of SQL Server. It's important, because SQL Server 2012 makes the job much easier (and will also run much faster, by dodging a self join). (As Kalman said, the OVER clause contributes to this answer).
Both approaches below avoid needing the cursor at all. (There was part of your explanation I didn't understand fully, but I think these suggestions work regardless)
Here's a SQL 2012 answer, using LAG() to lookup the previous 1 and 2 donation codes by Donor: (EDIT: I overlooked a couple things in this post: please refer to my follow-up post for the final/fixed answer. I'm leaving this post with my overlooked
items, for posterity).
With Results_Interim as
Select *
, count('x') over(partition by donor_number) as Ct_Donations
, Lag(test_code, 1) over(partition by donor_number order by donation_date ) as PrevDon1
, Lag(test_code, 2) over(partition by donor_number order by donation_date ) as PrevDon2
from RESULT_SAMPLE
Select *
, case when PrevDon1 in (9, 10, 11) and PrevDon2 in (9, 10, 11) then 'Q'
when PrevDon1 in (9, 10, 11) then 'A2'
when PrevDon1 is not null then 'A1'
End as NEWSTATUS
from Results_Interim
Where Test_result_Date >= '2014-01' and Test_result_Date < '2014-02'
Order by Donor_Number, donation_date
And a SQL 2005 or greater version, not using SQL 2012 new features
With Results_Temp as
Select *
, count('x') over(partition by donor_number) as Ct_Donations
, Row_Number() over(partition by donor_number order by donation_date ) as RN_Donor
from RESULT_SAMPLE
, Results_Interim as
Select R1.*, P1.test_code as PrevDon1, P2.Test_Code as PrevDon2
From Results_Temp R1
left join Results_Temp P1 on P1.Donor_Number = R1.Donor_Number and P1.Rn_Donor = R1.RN_Donor - 1
left join Results_Temp P2 on P2.Donor_Number = R1.Donor_Number and P2.Rn_Donor = R1.RN_Donor - 2
Select *
, case when PrevDon1 in (9, 10, 11) and PrevDon2 in (9, 10, 11) then 'Q'
when PrevDon1 in (9, 10, 11) then 'A2'
when PrevDon1 is not null then 'A1'
End as NEWSTATUS
from Results_Interim
Where Test_result_Date >= '2014-01' and Test_result_Date < '2014-02'
Order by Donor_Number, donation_date -
Update column based on sum of data from another table
Hi We had two tables.
Table 1: matusetrans
ITEMNUM Location Quantity transdate
AM1324 AM1 2 12-4-12
AM1324 AM1 2 15-5-12
AM1324 AM1 3 10-6-12
AM1324 AM1 4 5-1-13
AM1324 AM1 2 13-3-13
AM1324 AM2 3 2-5-12
AM1324 AM2 2 12-7-12
AM1324 AM2 1 13-2-13
Table 2: Inventory
ITEMNUM STORELOC lastyear currentyear
AM1324 AM1 need sum(quantity) here need sum(quantity)
AM1324 AM2 need sum(quantity) here need sum(quantity)
We have to update the last year and current year columns with sum of quantities for each item from matusetrans table based on date at different location in Inventory table.
we had nearly 13,000 records(itemnum's with different location) in inventory table in DB we have to update entire records.
Any help...How to write an sql queries to update lastyear and currentyear columns with sum of quantities based on itemnum and location in Inventory table
Thanks
Edit/Delete MessageTry this
SQL> select * from matusetrans;
ITEMNU LOC QUANTITY TRANSDATE
AM1324 AM1 2 12-APR-12
AM1324 AM1 2 15-MAY-12
AM1324 AM1 3 10-JUN-12
AM1324 AM1 4 05-JAN-13
AM1324 AM1 2 13-MAR-13
AM1324 AM2 3 02-MAY-12
AM1324 AM2 2 12-JUL-12
AM1324 AM2 1 13-FEB-13
8 rows selected.
SQL> select * from inventory;
ITEMNU STO LASTYEAR CURRENTYEAR
AM1324 AM1 0 0
AM1324 AM2 0 0
SQL> merge into inventory i
2 using (
3 select itemnum
4 , location
5 , sum(decode(extract(year from transdate), extract(year from sysdate), quantity)) currentyear
6 , sum(decode(extract(year from transdate), extract(year from add_months(sysdate, -12)), quantity)) lastyear
7 from matusetrans
8 group
9 by itemnum
10 , location
11 ) t
12 on (
13 i.itemnum = t.itemnum and
14 i.storeloc = t.location
15 )
16 when matched then
17 update set i.lastyear = t.lastyear
18 , i.currentyear = t.currentyear
19 /
2 rows merged.
SQL> select * from inventory;
ITEMNU STO LASTYEAR CURRENTYEAR
AM1324 AM1 7 6
AM1324 AM2 5 1
SQL> -
How to use a USER_DATASTORE to index multiple columns in different tables
I would appreciate if somebody can give an example or point to links with examples on how to use USER_DATASTORE on multiple columns in different tables. THe Oracle Text documentation only shows multiple columns in the same table.
Thanks in advance.I am not sure why your getting the wrong results but you should seriously reconsider the approach your are taking. Using functions like this is very ineffecient and should be avoided at all cost.
-
How to make validation in Bean and select value from another table
I want to know how to select data from table in backing bean according to primary key i have
the problem is that
i have a table Employee_Salary contains Employee ids and their salary
Empoloyee_Salary table
Employee_ID Number
Employee_salary Number
And Another table Called Employees
Employees table
Employee_ID Number
IsManager Varchar2 its value is [*Yes or NO*]
and other columns that i don't care about this table
i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
*i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
cannot be less that 100
i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
i have to select IsManager from Employees Table to see if this manager or no
i want to know how to make this in a bean
i use jdeveloper 11g
and my project is ADF Fusion project
and the page that have the Emplpyee_Salary table is JSFF
thanks in advanceYou might want to write this code in a validator on the entity object if it should apply from every screen.
If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918 -
How to add the values of all selected columns in a table and display it ?
Hi all,
I am using jdeveloper 11.1.1.6.0
Page:
my page jsff page contains one ADF table and one textbox
DB:
i have two database tables A & B ,
i need 2 columns from each table . say (A.product_no ,A.product_name,B.prodeuct_price ,B.confirm)
here product_no is primary key and present in both tables.
i need to create a VO combining these two tables and put it as ADF table in a jspx page
Functionality :
my 'confirm' field is a checkbox field in table . whenever the checkbox is selected,
the corresponding price will be getting added and display it in a textbox.
Eg:
if my first 4 price values are 3000 , 2000 ,4000,2000
and if i select first 3 values , then the text box should contain 9000 value.
i need help ...
Problem:
i need help in creating VO and functionality partHi,
it is easy: create an entity object for every table and one view object where you select your both entity objects and join them in your select statement.
Your desired 'confirm' functionality could be achieved with helpp of view object transient attributes - for more information see: http://docs.oracle.com/cd/E21764_01/web.1111/b31974/bcquerying.htm#CHDHJHBI
Regards
Pavol
Maybe you are looking for
-
Report:Setting the line-count in the output automatically
i want to set the line-count in the report automatically irrespective of screen resolution.could you please explain.
-
Issue with bluetooth conection
Hi, I've been having problems with the conection of bluetooth in my car stereo. it pairs normally but after some time connected it suddenly disconnects (whenever I receive a phone call mostly) I never had this problem with kitkat. What can I do?
-
Not able to edit PO releases in the POS form
The user is not able see all the releases of a PO in the POS screen. There are 83 releases in which only 62 are visible for him. What could the cases stopping the user from viewing the releases? Edited by: user13162147 on Dec 16, 2010 1:37 PM
-
WU_TEST.fmb (webutil demo form) - where is it?
Would somebody point me to the location of the WU_TEST.fmb form (downloaded latest webutil - don't have this demo) Thanks in advance
-
Everytime I start my MAC, the Applications window opens. How do I prevent that from happening. I just want to see the Desktop with the normal Hardrives and folders I setup on the Desktop.