Concatenating columns in a query
Hello,
I am working on a SQL Query for one of my reports.
Which has four columns c1,c2,c3,c4. The value of Each of these columns is coming from an individual Subquery.
How can I combine these to display an output in a report.
Please advise,.
Thanks
Fm
Hi,
If c1, c2, c3 and c4 are all strings, then the way to concatenate them all together is
c1 || c2 || c3 || c4It doesn't matter where the strings come from: whether they are the results of scalar sub-queries (which, I believe is what you are saying they are), columns, literals, function results, or anything else. You can concatenate the actual expressions that produce the strings, for example
(SELECT ...) -- a scalar sub-query
|| (SELECT ...) -- another scalar sub-query
|| (SELECT ...) -- another scalar sub-query
|| (SELECT ...) -- another scalar sub-queryBut there might be a more efficient way to get the same results. If you'd like help, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
In Oracle, you don't have to worry about some of the strings being NULL. "x || NULL" is x.
Similar Messages
-
OBIEE Group By on 2 facts and concatenated columns from different dimensions
Hi
I have a different kind of problem involving 2 fact tables with different dimensional attributes.
Fact 1 has Dim Attributes ( Cust,Facility )
Measure - Gross Amount
Fact2 has Dim attributes (Cust,Facility and Risk Group )
Measure : Exposure Amount
Since we have 2 facts with different dimensions,
to exclude the 'Risk Group' dimension column from the group by for the Fact1,
we set the 'Gross Amount' measure to total level (Risk Group Dimension ) in contents tab.
So the values from both the fact tables appears in the same report correctly.
But in the same report we have another requirement where the rating column from the customer dimension has to be concatenated with the ratings column in the facility dimension.
We have to concatenate customer.rating with the facility.rating and display it in the report.
when we just pull the individual columns from the dimensions into the report it works fine.
But when we try to concatenate the 2 columns and show it in the report,
the concatenated column does not appear in the select or the group by in the SQL Fact2.( Generated by OBIEE )
The other fact1 has the concatenated column in the select as well as the group by clause ( Generated by OBIEE )
As a result the report shows the concatenated values only for the results from the Fact1. But the results from Fact2 does not have the concatenated column values.
The report should look like the below:
Custor.Name, Customer.Id, Facility.Name, Facility.Id, Customer.Rating/Facility.Rating, Risk Group, Gross Amount, Exposure Amount
=========== ========= =========== ========= ======================== ========= =========== ===============
JPMC 123 GROSS 123 08/10 LNL 45,000 25,000
CLAIRE 456 NET 456 07/10 RNK 50,000 30,000
Thanks,
ChandraAs suggested you really want to move your none-aggregated fact attributes to a logical dimension (using the same physical table as the logical fact). Map this in the BMM layer as a snowflake, Place a hierarchy on this dimension with (at minimum) Total -> Detail levels, then on the other fact table you want to include in the report, set the content level on your other fact measures to the 'Total' level for your new logical Dim and it will allow them to be present in the same report.
-
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 -
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] -
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.
-
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 -
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 -
Hi Gurus!
I'd like to hide a column for specifics users in a BW Query.
I flagged the InfoObject as Auth. Rel. and created an analysis authorization. I ran the query but I got "No authorization", when I checked the log I saw that the query is asking for full authorization value to that InfoObject. I tried with : (semi colon) value but I got the same result.
Is there any way to hide a column in a query (with authorization concept) avoiding to redisign a new query?
Thanks in advance.
Best regards,
Pepewhen I checked the log I saw that the query is asking for full authorization value to that InfoObject
Is there any way to hide a column in a query (with authorization concept) avoiding to redisign a new query?
For your existing query, above two are conflicting. So guess you have to move with redesign/new query.
Regards,
Arpan Paik
Maybe you are looking for
-
Hierarchy leaves have different InfoObject name than the value
Hi, I am working on an hierarchy and loaded data to BW. I noticed that when I expanded the tree, the right side of the leaves saids 0COSTCENTER but the left hand side of the leaves has the department values. Would this be a prolem for reporting or an
-
Determine if PO number has been used in a Sales Order for a customer....
We're able to perform some processing both before the Sales order is created and before the IDOC is updated, status-wise. One of the checks that we're performing is to determine whether the PO number supplied by the IDOC has been used in a order befo
-
Which is best for my Macbook, an inverter running off my socket in the rear of my Tucson marked 120w or a 12 volt charger. Anything made by Apple ? Bearing in mind we in South Africa get the ar** end of products and our Apple shops are a bit like Dis
-
Create a report using the HEAT Call Logging Systems Hours of Operation
In the HEAT Call Logging System we have set up the 'Hours of Operation.' Now when creating our Crystal Reports we would like to incorporate those hours of operation. What I am needing to know is how we can use the hours of operation we set up in HEAT
-
Does iCloud sync videos taken on my iPod touch?
Can anyone please tell me if iCloud syncs videos taken on my iPod touch and if so, where do I find them? Thank you.