Subtruction between 2 columns in a query
Greeting Gurus,
i have the following query and what im trying to do is subtruct "TOTAL'' from ''By_PERIOD''. Is it possible to do it under these names or should i include both the select's into a new Sum?Thanks for any help in advnance
select a.cat,c.com,a.cat_desc,a.acnt_code, b.descr,
Sum(d.bas_amount) AS TOTAL,
Sum((select d.bas_amount from so_budgets d1 where d1.acnt_code = d.acnt_code
and Trim(d.period) BETWEEN '2008001' AND '2008006' AND ROWNUM=1)) BY_PERIOD,
Sum((SELECT kl.amount FROM a01_a_salfldg@oracle_to_sun kl WHERE Trim(kl.accnt_code)=Trim(a.acnt_code)
AND ROWNUM=1)) AS actual
from so_budgets_cat a,a01_acnt@oracle_to_sun b,so_budgets_com c,so_budgets d
where trim(a.acnt_code)=trim(b.acnt_code)
AND a.cat=c.cat
AND TRIM(d.acnt_code)=trim(a.acnt_code)
GROUP BY a.cat,a.acnt_code,c.com,a.cat_desc,b.descr
order by a.cat,a.acnt_code,c.com,a.cat_desc,b.descr
-------------------------------------------------------
create another column in your sql statement
SELECT a.cat,
c.com,
a.cat_desc,
a.acnt_code,
b.descr,
SUM(d.bas_amount) AS total,
SUM((SELECT d.bas_amount
FROM so_budgets d1
WHERE d1.acnt_code = d.acnt_code
AND TRIM(d.period) BETWEEN '2008001' AND '2008006'
AND rownum = 1)) by_period,
SUM((SELECT kl.amount
FROM a01_a_salfldg@oracle_to_sun kl
WHERE TRIM(kl.accnt_code) = TRIM(a.acnt_code)
AND rownum = 1)) AS actual,
((SUM(d.bas_amount)) -
(SUM((SELECT d.bas_amount
FROM so_budgets d1
WHERE d1.acnt_code = d.acnt_code
AND TRIM(d.period) BETWEEN '2008001' AND '2008006'
AND rownum = 1)))) sum_tot_per
FROM so_budgets_cat a,
a01_acnt@oracle_to_sun b,
so_budgets_com c,
so_budgets d
WHERE TRIM(a.acnt_code) = TRIM(b.acnt_code)
AND a.cat = c.cat
AND TRIM(d.acnt_code) = TRIM(a.acnt_code)
GROUP BY a.cat,
a.acnt_code,
c.com,
a.cat_desc,
b.descr
ORDER BY a.cat,
a.acnt_code,
c.com,
a.cat_desc,
b.descr
Similar Messages
-
Access Summary column in a query
Hi All,
I am new to oracle reports. I am using report builder 10.1.2.0.2.
I have a summary column in my report. I would like to use this summary column in another query.
if is use this column directly in the query, i am getting the below error:
"Field 'F1' references column '<summary column name>' at a frequency below its group. "
Both these fields are in the same frame. In the object navigator, both are displayed under the same group name.
please let me know if there any way to access summary columns in another query.
Thanks.You can use a field from one query in another query as parameter, i.e. preceded by colon. To do this first create link of "Group to Query" type between the first query's group where the summary column is, and the second query.
-
How to make paragraphs line up between columns?
I want to make a 2 column chapter, with the text in each column in its own flow. But then I want some of the paragraphs to line up between columns.
So, like this:
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
yyyyyyyyy
yyyyyyyyy
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
I'm assuming I can't use side heads to put the first column text in, because the info on the left goes on for multiple paragraphs, and I can't seem to line up a block of paragraphs with the baseline of the appropriate right column text.
I used to do this in tables, like this:
xxxxxxxxxx ! yyyyyyyyy
xxxxxxxxxx ! yyyyyyyyy
xxxxxxxxxx ! yyyyyyyyy
! yyyyyyyyy
! yyyyyyyyy
xxxxxxxxxx !
xxxxxxxxxx !
xxxxxxxxxx !
xxxxxxxxxx ! yyyyyyyyy
xxxxxxxxxx ! yyyyyyyyy
...where the gridlines between rows and columns would be hidden. However, I sometimes need to print just the right column, which meant I had to remove the table. It's a 600-page document, I was looking for a more elegant solution.
Any suggestions?
I am using FM8.0(266) on Windows XP.If you take the sidehead approach that Niels suggest, you could do
this, but it would be a bit of maintenance.
Have your "xxxxx" flow content sit in text frames within anchored
frames. The anchored frames are then in a special conditionalized
paragraph ("z") in the *sidehead* before every "yyyy" flow section,
e.g.
z
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
yyyyyyyyy
yyyyyyyyy
z
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
z
xxxxxxxxxx yyyyyyyyy
xxxxxxxxxx yyyyyyyyy
The "z" paragraph is just a container for the anchored frames and
should contain no text.
When you hide the "z" tags, all of the "x" flow content will then
disappear as well. You'll have to manually customize the height of
each anchored frame/text frame pair though.
To adjust the spacings between the "y" flow to match at the bottom of
the anchored frames for the "x" flows, use the sidehead paratag ("Z")
and create space above overrides in this paragraph only to adjust the
vertical spacing to keep the x and y sections in sync. This way, you
have overrides confined to only one paratag.
To make maintenance easier, it might be worth creating a FrameScript
that would adjust the height of the anchored/text frame combo based
upon the amount of content in the instructor flow and then apply the
space above override to the anchoring paratag (z). -
Multiple Key figure in a single column of a query
Hi,
Is it possible to use muliple key figure like Amount and Qty field together in a column of a query?
Please advise,
Best Regards,
URHi,
You will be able to do it with the help of cell definitions.
Say,you have a structure in Rows :
A
B
For A ..in corresponding column cell,use cell definition with KF1
For B.....in corresponding column cell,use cell definition with KF2
this way,you will be able to see both in one column
I m not sure how much it is relavant to your requirement.But this is one way of gettin it -
Hello,
In a BW query, I need to add a column of text comments (for example, the description of a calculation, the unit used, ...). These texts are static, the queries will only be used as static reports (download scheduler), in excel and web, so we can not use any VB script.
Is it a way to add some text in a cell of a column, as in the following example (columns 2 and 3) ?
KF1 | Comment for KF1 | Euros | 12
KF2 | Comment for KF2 | % | 47
Thanks in advance
MichaëHi guys,
finally how you fix this problem?, I need to show a comment in a query column and i don't know if this is posible ¿?, I have a query inside of a wad and I want to show a comment in the columns of the query with the formula details.
Please let me know if you this is possible.
Thanks!, Kinds Regards -
How to provide space between columns in alv_grid_display?
hi,
gurus,
I want to provide space between columns in alv display how can i achieve that.
ex.
sno name street
thank u ,
shabeer ahmed.Hi..,
There you wl get column seperators with seperate blocks and cells in the grid anyway.
Maintain gap between columns is nothing but grid breaking, its may be possible with oops concept.
Let me know whats your requirement?
Thanks,
Naveen.I -
Creating an empty column in a query
Is there a way to place an empty column in a query? I would like to put acolumn with no information into the middle of a query. The reason is that the information that goes in that column is not available on any tables in my SQL databases.
SELECT
hier.dir_name
,hier.am_name
,hier.fm_name INSERT BLANK COLUMN HERE
,hier.tech_name
hier.tech_idHi
"no information" in database is usually NULL value. Is this what you are looking for?
SELECT
hier.dir_name
,hier.am_name
,NULL as fm_name
--,hier.fm_name INSERT BLANK COLUMN HERE
,hier.tech_name
hier.tech_id
[Personal Site] [Blog] [Facebook] -
Set Column width in query (not using SQL*Plus)
How can I Set Column width in query
I understand you can set column width using
column col1 FORMAT A5
select col1 from table1;But this only works in SQL*Plus
I want to be able to do this in a regular SQL query window (not in SQL*Plus), how can I do it.....
I am using a 'SQL window' in PL/SQL Developer IDE
and when I use this syntax it says:
ORA-00900: Invalid SQL statement
Any suggestions are appreciated...
thanks,
M.Did you try using RPAD or LPAD functions? They fill the unfilled part of a string with character you provide... either on right or left side depending on what function you use.
e.g.
SELECT RPAD('Smith', 10, ' ') Name FROM dual;http://www.adp-gmbh.ch/ora/sql/rpad.html
Edited by: Zaafran Ahmed on Nov 10, 2010 11:50 AM -
How can i remove the line between columns?
I'm laying out poetry and I only want one column--even in landscape mode. But in landscape mode there's still the line between columns that cuts through my text. I've tried dragging the line, clicking on it and deleting it. When I click on it two Xes appear on the top and bottom, but they don't appear to do anything.
I did a little more reading of threads and now I understand the approach.
Go to View/Layouts and click on any of the layouts which appear on the left. At that point you will have access to the full page template and may make any and all changes you wish.
Keep in mind that some elements will be locked requiring an Arrange/Unlock command before you can eliminat them.
In the end it will be very easy to create completely customized layouts, including background images, rules, etc. etc.
Good luck with the poetry. -
Multiple columns from a query sorted vertically
Is it possible to sort a query resultset vertically, with
multiple columns across the page, in the following manner, with
page breaks after 40 rows? I can get it to sort horizontally just
fine with tables, but how can it be done vertically as shown?
JONES, Abby JONES, Betty JONES, Dawn JONES, Frank
JONES, Adam JONES, Bill JONES, Debbie JONES, Gayle
JONES, Alice JONES, Bob JONES, Denton JONES, Henry
JONES, Ben JONES, Cathy JONES, Emma JONES, JohnThis will get you started. I assume you had the appropriate
order by clause in your query. I also assume you want 4 columns per
line.
My approach would be to convert the query to an array and
then output the array.
columns = 4;
maxrows = 40;
recordsperpage = columns * rows;
records = query.recordcount;
myArray = ArrayNew(2);
ThisColumn = 1;
ThisRow = 1;
if (records gt recordsperpage)
LoopTill = recordsperpage;
else
LoopTill = records;
for ( ii = 1; ii lte LoopTill; ii = ii + 1){
myArray[ThisRow][ThisColumn] = query.field[ii];
increment ThisRow;
if (ThisRow = MaxRows + 1) {
ThisRow = 1;
increment ThisColumn;
} // if
} // looop
You can do the rest -
hi, i am using oracle 10g database..
how to get the sum of column in union query ?
select * from (select 100 records from dual), (select 50 available from dual)
union
select * from (select 200 records from dual), (select 150 available from dual)
display should be like
records available
100 50
200 150
total 300 200thanks ...Peter vd Zwan wrote:
try this:Grouping by records will not produce correct results:
SQL> with a as
2 (
3 select * from (select 100 records from dual), (select 50 available from dual)
4 union
5 select * from (select 100 records from dual), (select 100 available from dual)
6 union
7 select * from (select 200 records from dual), (select 150 available from dual)
8 )
9 select
10 case when grouping(records) = 0 then null else 'total' end tot
11 ,sum(records) records
12 ,sum(available) available
13 from
14 a
15 group by
16 rollup (records)
17 ;
TOT RECORDS AVAILABLE
200 150
200 150
total 400 300
SQL> select case grouping(rownum)
2 when 1 then 'Total'
3 end display,
4 sum(records) records,
5 sum(available) available
6 from (
7 select * from (select 100 records from dual), (select 50 available from dual)
8 union
9 select * from (select 100 records from dual), (select 100 available from dual)
10 union
11 select * from (select 200 records from dual), (select 150 available from dual)
12 )
13 group by rollup(rownum)
14 /
DISPL RECORDS AVAILABLE
100 50
100 100
200 150
Total 400 300
SQL> SY. -
Retrieve varchar column from Oracle query in a resulset
Hi, I'am a begginer in JSP Technologies.
I've do a small jsp that opens a db connection to an oracle, execute a query a show results.
When the columns of the query are int I've no problem, the jsp show the columns of the resulset, but when the columns selected are varchars the jsp doesn't show anything....
Can anyone help me?
Example:
Table: CUSTOMERS
Col1 : ID_COSTUMER int
Col2: CUSTOMER_NAME varchar
<%
Connection canal = null;
ResultSet tabla = null;
Statement instruccion=null;
try { Class.forName("oracle.jdbc.driver.OracleDriver");
canal=DriverManager.getConnection("jdbc:oracle:thin:@XXXXXXXXXXXXXXXXXXXp");
instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
} catch(java.lang.ClassNotFoundException e){};
String Query = "SELECT ID_CUSTOMER FROM CUSTOMERS";
try { tabla = instruccion.executeQuery(Query);
out.println("<TABLE Border=10 CellPadding=5><TR>");
out.println("<TD>CUSTOMER</TD></TR>");
while(tabla.next()) {
out.println("<TR>");
out.println("<TD>"+tabla.getString(1)+"</TD>");
out.println("</TR>"); };
out.println("</TABLE></CENTER></DIV></HTML>");
tabla.close(); instruccion.close(); canal.close();}
catch(SQLException e) {};
%>Results:
CUSTOMER
1
2
3
4
Doing the change in query:
SELECT CUSTOMER_NAME FROM CUSTOMERS
I have not results....
Thank you.sorry, I misplaced an ending code bracket on last one
I'm not really familiar with doing this inside a jsp.. but there are a few things that you should try to make sure that it isn't a database problem before assuming it is a problem on your jsp.... It is possible you have already tried the following but just to make sure.
When you do the second query does the first two out.printlns that are before the while still output? If not then your query is incorrect.
Second I would try
String Query = "SELECT ID_CUSTOMER,CUSTOMER_NAME FROM CUSTOMERS";
try { tabla = instruccion.executeQuery(Query);
out.println("<TABLE Border=10 CellPadding=5><TR>");
out.println("<TD>CUSTOMER_ID</TD><TD>CUSTOMER_NAME</TD></TR>");
while(tabla.next()) {
out.println("<TR>");
out.println("<TD>"+tabla.getString(1)+"</TD>");
out.println("<TD>"+tabla.getString(2)+"</TD>");
out.println("</TR>"); };
out.println("</TABLE></CENTER></DIV></HTML>");I suspect this will also return nothing.. if that is the case then you need to check your database. If it does infact return values for the ID and nothing for the NAME then I'm not sure at this point what the problem is. -
How Can i add "DateDiff(day, T0.DueDate" as a column in this query?
How Can i add "DateDiff(day, T0.DueDate" as a column in this query?
SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
CASE WHEN T0.TransType=13 THEN 'Invoice'
WHEN T0.TransType=14 THEN 'Credit Note'
WHEN T0.TransType=30 THEN 'Journal'
WHEN T0.TransType=24 THEN 'Receipt'
END AS 'Document Type',
T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
WHERE (T0.MthDate IS NULL OR T0.MthDate > [%1]) AND T0.RefDate <= [%1] AND T1.CardType = 'C'
ORDER BY T1.CardCode, T0.DueDate, T0.Ref1Hi,
As you mentioned not possible to assign the dynamic column in the query.
will give you example for generate a dynamic column name in SQL query, using this example you can achieve your requirement.
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(C.Name)
from [History]
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT [Date],' + @cols +'
from
select [Date], Name, Value
from [History]
) x
pivot
max(value)
for Name in (' + @cols + ')
) p '
execute(@query) -
How to return Parameters values as a column in a query?
Hi All,
I have number of parameters in a report.
I need to return its interred values as a column in a query to use this column in a chart.
I want this column to be the second one in this query:
SELECT ROWNUM
FROM ALL_OBJECTS
WHERE ROWNUM <= 10
That is if there is any way to use these parameters directly as a column in the chart no need for the previous statement.
Note: I am using Reports 6iDear sir
You can enter parameter as column in query like
select :parameter p1, &hexadecima_paramataer p2, empcode
from emps;
that query make parameter as query column .
&hexadecimal paramater can refer to database column of table emps
and :paramater can refer to static string -
How to implement 'Quick Select' column in a query result table?
Hi,
I have a requirement in OAF to design a search page with 'Quick select' column.
One of the column in the query result table should be a quick select.
Once user clicks on the quick select column, we have to navigate back to the previous page with the row value selected.
Can anyone help me in this.
Thanks.Also refer the search exercise in the toolbox tutorials.
you can implement the quick search in the same way as update and delete buttons.
--Prasanna -
Hi experts,
I am doing a query and I need to do something that I am not sure if it can be done. I have one characteristic (0COUNTRY) in the query and one variable to filter by Sales Organization. What I need to do is to have a new column in the query that will show Local market in case 0COUNTRY is the same as the Sales Organization country attribute, and Export market when it is different. Does anybody know if this can be done in BeX analyzer?
Any hint would be appreciated.
Thanks and regards,Hi,
U can achieve this by using virtual characterstics.Add another characterstics in the cube with length 20 char (Say ZTEXT).
Code in the exit RSR00002 with program ZXRSRU02 for virtual characterstics.
Here u can put the logic as follows:
Read value 0COUNTRY compare the value with SALESORG 0country attrtibute value from master data table.
if same ZTEXT = 'Local market
else.
ZTEXT = 'Export market
There will be some performance issue but if the requirement like this u can try with this.
Thanks,
Debasish
Maybe you are looking for
-
I have a problem that is somewhat two-fold. I'm trying to play a video on a digital frame. It only plays MPEG1, 2, and 4 with a resolution of 1024x768 (my video is 720x480). Whenever I play my video it distorts the aspect ratio slightly, but noticeab
-
How can i delete a picture from camera roll without deleting everywhere
how can i delete a picture in camera roll without deleting everywhere
-
Everytime Adobe Reader 9 is extracting installation files, about half way, Windows XP SP3 reboots. Therefore, I am unable to install the Adobe Reader on my computer. I would appreciate any help you can provide.
-
Does anyone else find Bt business billing grossly incompetent?? I've had 10 months of billing errors, incurred hundreds of pounds of fees and constantly get calls to pay for a website that doesn't work. I've paid for changes and nobody has called me.
-
VC 7.2 personalize table settings - hide columns not working
I have table setting property activated in CE 7.2 VC UI , when I hide the columns, i am able to hide for that session, if I logout and login, I am not able to see the settings, all the columns are visible. Are these settings are per session ? it is n