Reading count of a query in formula columns
I need to supress a field/label from being displayed in the report output if the count of rows returned from another query is 0. I was thinking of defining a formula column that will have the count. Then can I use that formula column in the trigger of the field/label that I want to supress?
I am all set. Was able to do with Summary columns.
Message was edited by:
M@$$@cHu$eTt$
Dates should be compared with dates values. Don't use to_char to compare date values.
And dont use "TYPE" as a column name - it is a reserved key word..
select count(type), type
from ebizp.bchistevent
where (
type = 'com.avolent.apps.event.LoginEvent'
or type = 'com.avolent.apps.event.LogoutEvent'
AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
and (
bucket = to_char(sysdate-1, 'YYYYMM')
or bucket = to_char(sysdate, 'YYYYMM')
or bucket = 0
GROUP BY type;And you can simplify the query
select count(type), type
from ebizp.bchistevent
where type in
('com.avolent.apps.event.LoginEvent','com.avolent.apps.event.LogoutEvent')
AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
and bucket in
(to_char(sysdate-1, 'YYYYMM'),to_char(sysdate, 'YYYYMM'),'0')
GROUP BY type;Edited by: jeneesh on Feb 19, 2013 2:42 PM
Similar Messages
-
How to use a Formula Column in the main query?
Hi All,
I've tried to use a formula columns defined in some query in the condition of that query like this:
where (:cf_ex - :cf_ex2) >= 5
but when I run the report no data returned! Why? and how to use it the condition of the query?
Note: I'm using Forms 6iwhere (:cf_ex - :cf_ex2) >= 5You cannot do that. Formula columns are not part of the select statement (which runs in the database), but are processed in the report.
When you created this query, my guess is that you got the message "Note: the query Q1 has created the bind parameter(s) cf_ex, cf_ex2". Check these User Parameters in your data model. So, you are actually referencing user parameters in the query, not formula columns.
I made a computations and things using PL/SQL that can't be done in the select statement in the data model!If it's pl/sql you can probably use that in your query. Create some database functions for cf_ex and cf_ex2 and use these in your query. -
Can we use formula column in lexical parameter in sql query ...
hi
can we use formula column in lexical parameter in sql query ...
as example
i want to give
select * from & c_table
forumula
function c_table
if :p_sort = 1 then
return 'dept'
else
return 'emp'
end;
c_table formula column
is this possible ...
i have such example in oracle apps reports
if i try in ordinary report usinf emp table it show error ..
how we can give formula column...
please help me in this regard...
Edited by: 797525 on Feb 20, 2012 9:31 PMthanks sir,
iam not exactly saying select * from &c_table but some thing that like columns in select stmt also will be populated in user_parameters ,there are lot of table select.......from mtl_demand md, mtl_system_items msi, mtl_txn_source_types mtst, mtl_item_locations loc &C_source_from &C_from_cat
&c_source_from and &c_from_cat formula column and there are defined at report level only ......
pl/sql code &c_source_from is
function C_source_fromFormula return VARCHAR2 is
begin
if :P_source_type_id = 2 then return(',MTL_SALES_ORDERS mkts');
else if :P_source_type_id = 3 then return(',GL_CODE_COMBINATIONS gl');
else if :P_source_type_id = 6 then return(',MTL_GENERIC_DISPOSITIONS mdsp');
else if :P_source_type_id = 5 then
if :C_source_where is null then
return NULL;
else
return(',WIP_ENTITIES wip');
end if;
else if :P_source_type_id = 8 then return(',MTL_SALES_ORDERS mkts');
else if :P_source_type_id is null then
return(',MTL_SALES_ORDERS mkts,
MTL_GENERIC_DISPOSITIONS mdsp,
GL_CODE_COMBINATIONS gl ');
else null;
end if; end if; end if; end if; end if; end if;
RETURN NULL; end;
this is forumula column i hope that you understand what iam saying
please help me in this regard....
thanking you... -
how can ı find column count of dynamic query
is there a simple way
thanksYou can use DBMS_SQL to facilitate this:
CREATE OR REPLACE FUNCTION count_sql( p_sql IN CLOB )
RETURN INTEGER
AS
lv_cursor_id INTEGER;
lv_columns DBMS_SQL.DESC_TAB;
lv_column_count INTEGER;
BEGIN
-- Open Cursor
lv_cursor_id := DBMS_SQL.OPEN_CURSOR;
-- Parse Cursor
DBMS_SQL.PARSE
( c => lv_cursor_id
, statement => p_sql
, language_flag => DBMS_SQL.NATIVE
-- Describe Columns
DBMS_SQL.DESCRIBE_COLUMNS
( c => lv_cursor_id
, col_cnt => lv_column_count
, desc_t => lv_columns
-- Close Cursor
DBMS_SQL.CLOSE_CURSOR(lv_cursor_id);
RETURN lv_column_count;
END count_sql;
/Example:
SQL > SELECT * FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL > SELECT count_sql('SELECT dummy, dummy, CASE WHEN dummy = ''X'' THEN 1 ELSE 0 END AS col FROM DUAL') FROM DUAL;
COUNT_SQL('SELECTDUMMY,DUMMY,CASEWHENDUMMY=''X''THEN1ELSE0ENDASCOLFROMDUAL')
3
SQL > SELECT count_sql('SELECT dummy, dummy, dummy, ''Y'' FROM DUAL') FROM DUAL;
COUNT_SQL('SELECTDUMMY,DUMMY,DUMMY,''Y''FROMDUAL')
4Hope this helps! -
Using Sybase query in Placeholder/Formula columns
Hi,
This is addendum to the post subjected as "JDBC query with Sybase database".
I am working with 9i Reports builder conecting to Sybase db through jdbc-odbc component. I can execute any statement in the form of query / procedure in jdbc query wizard.
I would like to know, how can i give/execute sybase compliant sql statements in placeholder, formula or for that matter any other place in reports builder.
Say, I have selected a column of in char format "020925" which represents a date of 25th Septemeber'2002. I want to give a statement like, "convert(datetime,'020925')", which converts to date format.
How can I specify this statement in a formula column.?? (formula column plsql editor recognize only oracle related statements)
Thanks & Regards
AnandHi Sachin,
So you mean to say, any other feature of Reports builder can't be used along with Sybase db. say triggers, local procedure / functions, etc.,
Is there any workaround to this setback?
Rgds
Anand -
Formula column help needed(urgent)
Hi ,
I am using the data template for generating XML data.
BIP provided functions like SUM(), AVG(), COUNT(), MAX(), etc to use as
below
<group name="G_DEPT" source="Q1">
<element name="DEPT_NUMBER" value="DEPTNO" />
<element name="DEPTSAL" value="G_EMP.SALARY" function="SUM()"/>
<group name="G_EMP" source="Q2">
<element name="EMPLOYEE_NUMBER" value="EMPNO" />
<element name="NAME" value="ENAME"/>
<element name="JOB" value="JOB" />
<element name="SALARY" value="SAL"/>
</group>
</group>
but suppose if I want to do a sum like
Sum(ALLdebits - All credits - All refunds).
We use to have formula good old formula column. like in ORACLE Reports...
below is my query in the data template....can someone please suggest?
<dataTemplate name="R007" dataSourceRef="xyz">
<properties>
<property name="include_rowsettag" value="false"/>
<property name="include_rowtag" value="false"/>
<property name="xml_tag_case" value="as_are"/>
</properties>
<parameters include_in_output="false">
<parameter name="DATE_FROM" dataType="varchar2" include_in_output="false"/>
<parameter name="DATE_TO" dataType="varchar2" include_in_output="false"/>
<parameter name="BANK_GIRO_NUMBER" dataType="varchar2" include_in_output="false"/>
</parameters>
<dataQuery>
<sqlstatement name="Q1">
<![CDATA[SELECT
DISTINCT
SYSDATE todayDate
,substr(trim(CR_BG_NO),3,8) creditorBGNumber
,CREDITOR_SHORT_NAME creditorName
,COUNT(*) itemCount
FROM
R00777_REPORT R1
WHERE
R1.TXN_DATE BETWEEN TO_DATE(:DATE_FROM,'YYYY-MM-DD') AND TO_DATE(:DATE_TO,'YYYY-MM-DD') AND
R1.CR_BG_NO = :BANK_GIRO_NUMBER
GROUP BY
substr(trim(CR_BG_NO),3,8)
,CREDITOR_SHORT_NAME]]>
</sqlstatement>
<sqlstatement name="Q2">
<![CDATA[
SELECT
TXN_DATE
,substr(trim(CR_BG_NO),3,8)
,PAYMENT_TYPE
,TXN_SERIAL_NO
,decode(PAYMENT_TYPE,'AGDEBIT_TRANSFER',DR_TXN_AMOUNT,'AG_REFUND',-RE_TXN_AMOUNT,'AGCREDIT_TRANSFER',-CR_TXN_AMOUNT)
SIGN_AMOUNT
FROM
R00777_REPORT R2
WHERE
R2.TXN_DATE BETWEEN TO_DATE(:DATE_FROM,'YYYY-MM-DD') AND TO_DATE(:DATE_TO,'YYYY-MM-DD')
AND R2.CR_BG_NO = :BANK_GIRO_NUMBER
]]>
</sqlstatement>
</dataQuery>
<dataStructure>
<group name="response" source="Q1">
<group name="head" source="Q1">
<element name="itemCount" value="itemCount"/>
<element name="todayDate" value="todayDate"/>
<element name="creditorBGNumber" value="creditorBGNumber"/>
<element name="creditorName" value="creditorName"/>
</group>
<group name="list" source="Q2">
<group name="listItem" source="Q2">
<element name="transactionDate" value="TXN_DATE"/>
<group name="transactions" source="Q2">
<group name="transaction" source="Q2">
<element name="transactionType" value="PAYMENT_TYPE"/>
<element name="serialNumber" value="TXN_SERIAL_NO"/>
<element name="amount" value="SIGN_AMOUNT"/>
</group>
</group>
<element name="netSum" value="transaction.SIGN_AMOUNT" function="SUM()"/>
</group>
</group>
</group>
</dataStructure>
</dataTemplate>Hi Rainer,
Many Thanks for your reply
I had done all the calculations in the report view earlier
and when i accessed it in the data template as follows
<element name="netSum" value="netSum" />
the xml output that i got was like
<R007>
<response>
<head>
<itemCount>8</itemCount>
<todayDate>2009-02-05T15:50:12.000+01:00</todayDate>
<creditorBGNumber>01829209</creditorBGNumber>
<creditorName>ANDROMEDA</creditorName>
</head>
<list>
<listItem>
<transactionDate>2008-09-03T00:00:00.000+02:00</transactionDate>
<netSum>-6647999</netSum>
<transactions>
<transaction>
<transactionType>AGCREDIT_TRANSFER</transactionType>
<serialNumber>5</serialNumber>
<amount>-1687200</amount>
</transaction>
</transactions>
</listItem>
</list>
</response>
</R007>
But the output that i want is something like this
<R007>
<response>
<head>
<itemCount>8</itemCount>
<todayDate>2009-02-05T15:50:12.000+01:00</todayDate>
<creditorBGNumber>01829209</creditorBGNumber>
<creditorName>ANDROMEDA</creditorName>
</head>
<list>
<listItem>
<transactionDate>2008-09-03T00:00:00.000+02:00</transactionDate>
<transactions>
<transaction>
<transactionType>AGCREDIT_TRANSFER</transactionType>
<serialNumber>5</serialNumber>
<amount>-1687200</amount>
</transaction>
</transactions>
<netSum>-6647999</netSum>
</listItem>
</list>
</response>
</R007>
Hence I used the BIP built in template function like this
<element name="netSum" value="transaction.SIGN_AMOUNT" function="SUM()"/>
but the sum() function is adding up all amounts as expexted,I want
the above newsum value as
Sum(AGdebit-AGCREDIT-AG_refund). -
Hi all!
I am using Report Builder 6i.
My report has several Groups (shown below)(that are user created, ie. not created due to the query).
Group_Organiser1
------Group_Organiser2
------------Group_Organiser3
-------------------Group_Organiser4
I have a Formula Column(FC) in Group_Organiser1. I want this FC to be executed only once, regardless of the number of rows included in/by the group. Hence, i want the FC to execute only when the value for Organiser1 changes (Eg. if there are 4 rows with Organiser1 = O1 and another 3 rows with Organiser1 = O2, I want the FC to execute only once when value changes from O1 to O2).
Currently the FC executes each time a row (that meets the grouping criteria, ie. 4 times for O1) is included in the group.
Hope this is enough information to solve this problem.
Eagerly waiting for any response...
Thank You.
Message was edited by:
OneThanx Aguero for your reply but sorry to say it does not solve my problem.
I really need to control the number of times the FC executes because if it executes too early (or too often) it does not count all the people below Organiser1, hence i need it to execute just before the value for Organiser1 changes.
This is my 'program logic' for the FC:
-depending on who(hence designation) is retrieved below Organiser1, increment the User Parameters(UP) :AC, :DC, :MOMM etc (which indicate/represent the various designations).
-then when Organiser1 is about to change, using the non-zero UP return an output of the form "AC: 1, DC: 3, MOMM: 2"; and also reset the UPs to 0 (zero).
So, you can see that if the FC executes too early (or too often), the UPs are reset too early.
To give an analogy, my requirement (for the FC) is similar to 'Reset At' property of Summary Columns; my FC needs to Reset At/Execute only when Organiser1 changes.
(Another problem with what Aguero has suggested is that Organiser1 values are retrieved from the database so i have no way of knowing who is going to be retrieved.)
Thank You. -
How to make an order on repeating frame using Formula Column?
Hi All,
I have a repeating frame dependent on some query, how to make an order on this repeating frame using a formula column defined in its group and dependet on values from the query?
Note: I'm using Reports 6iPlace your formula column at the top of the itm group and set the BREAK_ORDER to assc.. or desc...
Hope this helps
Hamid
if problem solved, close the thread. -
How to add a formula column in a report
Hi
I have made a report based on a query.
There are 3 columns in the query and all the 3 are displayed.
Now I want to add a new column (fomula column) to the report.
I want to write a query inside the formula column. To execute the query col1, col2 and col3 values are required in the formula column.
Could you please tell me how to add a formula column in the report and how to pass database column value to inside the formula column
regardsHere is how you would create a formula column:
Open data model of the report.
Formula column button is on the left side of the tool palette.
Click on that button.
Now click in the query group where you want to place the formula column.
You would see a new field something like CF_1. That is the formula column.
Double click on the field CF_1. It will open property inspector.
You would see, Datatype of the formula column is Number. Change this as per your requirement.
Double click on PL/SQL Formula property. It would open up a editor. Here you can write the code.
And now to access the data model column here, you can use : and column name. i.e. :col1 or :col2, etc
And remember you have to return the value back to the formula column. Like this: RETURN(some value).
You can also take a help from here:
http://download.oracle.com/docs/html/B13895_01/orbr_howto.htm#sthref1309
Hope this helps. -
Formula Column help please - URGENT
I'm trying to create a formula column as follows:
function NO_REPLIESFormula return Number is
NOREPLY number;
begin
SELECT COUNT(reply) INTO NOREPLY
FROM letters
WHERE reply = 'N'
GROUP BY ltrtype, batch;
RETURN (NOREPLY);
end;
This PL/SQL compiles fine, but when I run the report, I get the following messages:
REP-1401 no_repliesformula FATAL PL/SQL error occured. ORA-01422 exact fetch returns more than requested number of rows.
If I remove the GROUP BY ltrtype, batch, I don't get the error messages, but the result I get is the total no_replies instead of the total no_replies for each ltrtype/batch grouping.
Could someone please help me with this?
Thank you.Hi irish,
I think i am not sure about what you are trying to say, but let me guess, You want the values to be return on the bases of "ltrtype, batch". Which mea that you want more then one values, i mean there can be more then one Groups based on ltrtype and batch. and you want to display these values with repective record???
If i am right, then there is a fault in your code, and that is , you are not specifing in your code that which value is to be diplayed with which record in this report. For that there must be ltrtype, batch colums displayed in the report, you must add those values in your Code in the query, i.e.
function NO_REPLIESFormula return Number is
NOREPLY number;
begin
SELECT COUNT(reply) INTO NOREPLY
FROM letters
WHERE reply = 'N' and ltrtype= :V_ltrtype and batch=:v_batch;
RETURN (NOREPLY);
end;
Where :V_ltrtype and :v_batch are the run time values of each records displayed in the report.
Remember that if you don't sepecify this then your code will return as many records as many distich values of ltrtype, batch. and your variable NOREPLY can hold only one value at a time. I hope you understand both, Solution and the logic behind the error.
Please correct me if i am wrong.
Thanks.
Mohib ur Rehman -
Formula Column in Matrix Report (Running Balance)
Hi all. I hope somebody can help me.
I am working on a matrix report using multi-query data models. The report has 2 groups in the horizontal axis and 3 groups in the vertical axis. The intersection is not just a single row but may consist of multiple rows.
My problem is this. I want to create a column in the intersection which is obtained by using a column value from the lowest group in the vertical axis and a summary column obtained from the rows of the intersection.
Here's what my report looks like:
2002 (accross)
2002(down) january february (accross)
January (down) payments balance payments balance
loan #1 10,000 500 9,000 200 8,800
500
loan #2 5,000 100 4,900 200 4,700
February
loan #3 3,500 0 3,500 50 3,450
loan #4 4,200 0 4,200 0 4,200
As you can see, the loans are grouped by month and year. And the payments are grouped for the month and year too.
The data model is :
For Query 1 (Vertical Axis),
1st group - Loan Yr
2nd group - Loan Mo
3rd group - Loan # and amount
For Query 2 (Horizontal Axis)
1st group - Payment Yr
2nd group - Payment Mo
Intersection Group - Payment Amount
My problem actually is how to compute for the running balance of the loan for each month in the horizontal axis. Ive already created a cross product summary to get the running total of the payments made for the month. I tried creating a formula column to for the running balance by subtracting it from the loan amount but i get the error "incompatible frequency"
I hope i have described my problem well and thanks for the helpThe problem is that you're trying to reference dimension columns(loan Amount) in the calculation of matrix cell values. You can only reference other matrix cell values or cross product columns (summary, formula, placeholders) when calculating matrix cell values. Try moving the (loan Amount) column down to the matrix cell - something like:
For Query 1 (Vertical Axis),
1st group - G_LoanYear(LoanYr)
2nd group - G_LoanMonth(LoanMo)
3rd group - G_LoanNumber(Loan#)
For Query 2 (Horizontal Axis)
1st group - G_PaymentYear(PaymentYr)
2nd group - G_PaymentMonth(PaymentMo)
Intersecion /Detail Group - G_Details(PaymentAmount, LoanAmount)
Then create the following Matrix summary columns:
A running summary - CS_Payments:
- Product Order: G_LoanYear G_LoanMonth G_LoanNumber G_PaymentYear G_PaymentMonth
- Source: PaymentAmount
- Function: Sum
- Reset At: G_LoanNumber
The total amount per loan - CS_TotalPayment:
- Product Order: G_LoanYear G_LoanMonth G_LoanNumber
- Source: LoanAmount
- Function: First
- Reset At: G_LoanNumber
The value of the loan after each payment - CF_Countdown:
- Product Order: G_LoanYear G_LoanMonth G_LoanNumber G_PaymentYear G_PaymentMonth
- PL/SQL Formula:
function CF_CountdownFormula return Number is
begin
return(:CS_TotalPayment - :CS_Payments);
end;
You should then be able to display "CF_Payments" and "CF_Countdown" in the matrix cell to show how much has been paid and how much is still owed.
You can still have another "loan amount" as a dimension column - you just don't need to use it when calculating the values in the cell. -
Can formula column values be used as parameters
Post Author: vdm
CA Forum: Formula
Hi,
I have various formula columns setup in my crystal report, these formula columns act as prompts when end users run the report. i am using crystal reports xi and sql server databse.
Now I would like to use these formula columns to restrict my result set. basically, these should act as predicates (where clauses) to my query.
Is there a way to pass formula columns as parameters to stored procedures or to commands or to simpy add them to a sql query ?
thanks in advancePost Author: foghat
CA Forum: Formula
Have you tried adding the formula fields as a filter in the Record Selection Formula editor?So Report --> Selection Formulas --> Recordand add: {database.field_a} = and {database.field_b} = and so on -
Count(*) with nested query
Hi,
I have a question about the count(*) with nested query.
I have a table T1 with these columns:
C1 number
C2 number
C3 number
C4 number
C5 number
(The type of each column is not relevant for the example.)
This query:
select C1, C2, C3, C4
from T1
group by C1, C2
it's not correct becausa C3 and C4 are not columns specified in the GROUP BY expression.
If if run this query:
select count(*)
from (select C1, C2, C3, C4
from T1
group by C1, C2)
I haven't an error message (the result is correctly the number of records).
Why?
Thanks.
Best regards,
LucaBecause you are just selecting count(*) and none of the columns from the subquery, Oracle is optimising it by ignoring the selected columns and just running the sub query with the group by columns. I know it seems odd, but if you take a basic example:
SQL> ed
Wrote file afiedt.buf
1 select count(*)
2 from (select empno, sal, mgr, deptno
3 from emp
4* group by deptno)
SQL> /
COUNT(*)
3... all columns but deptno are ignored
... but if you include one of the other columns, even if you group by that column...
SQL> ed
Wrote file afiedt.buf
1 select count(*), empno
2 from (select empno, sal, mgr, deptno
3 from emp
4 group by deptno)
5* group by empno
SQL> /
group by empno
ERROR at line 5:
ORA-00979: not a GROUP BY expression
SQL>... the error returns, because you're forcing oracle to include the column in the subquery. -
Formula Columns in Data Template
Hi,
Is it posiible to have formula columns in data template apart from summary columns.please suggest.
RegardsYou can put those formula-logic in sql query.
summation/avg functions can be used directly in element. -
Applying order by for the data comming from the formula column
Dear Friends,
I am having a report in which some of the columns in which data is comming from the formula columns,but i need the data in asc order.
How can i do it.
Please advice.I am having a report in which some of the columns in
which data is coming from the formula columns,but i
need the data in asc order.Lets say you have this query:
select empno, sal, comm from emp
And you have empno, sal, comm and a formula column 'f_percentage' in one group. Add one dummy column in the query, like this:
select 'temp' temp, empno, sal, comm from emp
Move this 'temp' column into the second group (drag and drop outside the first group). You don't have to create repeating frame/or need to show this 'temp' column on the report.
Now if you use break order on formula column, that should work. Make sure you have break order on other columns also. Arrange items (change order) in data model as you needed. Run your report before and after this change and make sure you have same number of rows before and after this change.
(from reports builder's help)
"Break Order has no effect on columns that belong to the lowest group of a particular query. Break Order only affects columns in groups that are above the lowest child group of a query"
Maybe you are looking for
-
V3 Printer driver on Windows Server 2012
Hello there..... I have installed Print services on Windows Server 2012. I have read several forum and found that it is a best practice to install V3 drivers if workstations run on Windows 7. Our all of workstations have windows 7 so I want to instal
-
In mdx how to get max date for all employees is it posible shall we use group by in mdx
in mdx how to get max date for all employees is it posible shall we use group by in mdx example empno ename date 1 hari 12-01-1982 1 hari 13-06-2000 by using above data i want to get max data
-
Disable Deletion in Delivery Document
Hi All, I want to prevent Delivery Document to be Deleted by User, how can I disable the Delete Option in Delivery Document? At the moment I cannot create a Transaction Variant for it Any help will be appreciated
-
Rotating a circle using mouse coords.
I'm trying to rotate a circle. I want the circle to rotate in relation to the mouse movement across the y axis. Here is my code so far: onClipEvent (enterFrame) { _root.xVal = Math.round(_root._xmouse-this._x); _root.xMove = Math.round(_root.xVal/10)
-
Making 3D animated effects for photos
Are you able to create 3D photo effects, a la Riding Giants, The Kid Stays in the Picture, etc...by just using PhotoShop and FCE? (not just a simple ken burns effect) or is this something that has to be done in AfterEffects? Does Motion allow you to