Need Help on Filtering a column
Hi below is my requirement.
ColA ColB ColB
In the above, both the column 2 and 3 are the same columns, but i need to filter the column 3 alone based on another column. Please help.
Hi,
Write a case statement on 3rd column ...
case when table1.status = 'Complete' then value(2nd col) end
or
case when table1.status = 'Complete' then value(2nd col) else null end
Updated Post
Can you paste your code (case statement)
case when table_name.status ='Complete' then table_name.value end
or
case when table_name.status ='Complete' then table_name.value else null end
Cheers,
Aravind
Edited by: Aravind Addala on May 17, 2011 11:48 PM
Similar Messages
-
Need help in writing NVARCHAR2 column to an excel sheet
Hi All,
I have a NVARCHAR2 column in my table. I want to store the data present in the column into an excel file. When i write the data to an excel file the data is getting converted to some other form. It's not in human readable form.
Language is not fixed for the column.
I need help in storing the NVARCHAR2 data into an excel file without any implicit conversion done by the oracle.
Please help.
Thanks,
Girish G
Edited by: Girish G on Jul 14, 2011 2:02 AMExport data to BLOB (csv)
-
Need help on getting the column names of Tabletype
I have a table Mapping with the following values: This Mapping table contains the table names (in Tabname) and the column names(colname) of various tables and values(ValuesTobeFilled) for the columns.
I have to insert into the tables present in the Tabname field with the values present in the ValuesTobeFilled in the columns present in the Colname field.
Note: The Mapping table need not contain all the columns of the base table. The columns that are not present can be filled with null. And this mapping table is not fixed i.e. rows can be inserted/deleted frequently.
Sample values in mapping table:
Tabname Colname ValuesTobeFilled
sample_items Eno Corresponding Expression to get the values from XML input
sample_items Ename Corresponding Expression to get the values from XML input
XXX YYY Corresponding Expression to get the values from XML input
Before filling in the actual tables, I have to store the entire data temporarily and I have used a tabletype declared as follows:
TYPE T_sample_items IS TABLE OF sample_items%ROWTYPE INDEX BY BINARY_INTEGER;
l_sample_items T_sample_items;
Where the table sample_items have the following columns:
• Eno
• Ename
• Eaddress
• Eemail
So, the tabletype should be filled as:
Eno Ename Eaddress EEmail
1 XXX - -
I have declared a cursor to select the values from mapping table and I need to fill in the ValuesTobeFilled values to the corresponding table.
CURSOR c_xpath (c_tname mapping.TABNAME%type)
IS
select * from mapping where tabname = c_tname;
CURSOR c_tables
IS
SELECT DISTINCT TABNAME FROM mapping;
FOR crsr IN c_tables
LOOP
p_tname := CRSR.TABNAME;
FOR csr IN c_xpath(p_tname)
LOOP
IF l_xml_doc.EXISTSNODE(CSR.XPATH_EXP) = 1
THEN
l_node_value := l_xml_doc.extract(CSR.XPATH_EXP).getStringVal(); -- This is the value to be stored in the corresponding column
ELSE
l_node_value := NULL;
END IF;
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).name := l_node_value;
END IF;
END LOOP;
END LOOP;
And I need to eliminate hard coding while comparing the column names (in the following piece of code) as the Mapping table values are subject to insertion/deletion:
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).ename := l_node_value;
END IF;
I need to insert the values directly into the tabletype without this hardcoding. Please suggest me ways to compare the mapping table values with the field (column) names of the tabletype. If it is not possible using tabletype, please suggest any other ways of fixing the problem.
Many thanks,
GopiI take it this isn't going to be a serious production system at the end of the day?
Storing metadata in tables for extraction and insertion of data is just wrong in so many ways. It smells heavily of Entity Attribute Value modelling, which is the most wrong way to use a relational database and is known to have major performance implications and be liable to bugs and issues. The idea that EAV modelling allows for 'generic' databases where new data items can be added flexibly later on without having to change code is usually justified with an excuse of "it means we don't have to update all our tables when we want a new column" which is easily countered with "if you're adding a single column a good relational design wouldn't require you to add it to more than one table anyway in most cases".
Just what exactly are you trying to do and why? There has to be a better way. -
Need help on filtering out one record from a report and open in new page
Hi I am new and embarrassed to write in the forum asking silly questions. Thing is I am learning all from scratch without help from anyone. I have created a database (have previous knowledge only from Access) and have managed to create a beautiful report from a search filter. This report lines up several records matching what I needed. Now, I want to make the whole report with hyperlinks to a detailed page on each of the records in the report. I have tried using the feature where one can make one column hyperlinked and redirect to a new page, where I am getting all the records again - instead of only getting the record I am clicking on. I have looked and looked in the forums without finding solution and I have tested and tried various methods without luck. I am suspecting that I need some sort of knowledge on how to write a select query with where conditions that can apply to filtering out a record from one report to get another detailed on only one object (i.e. record). :/ Stupid or what?
Hrefna.
What you need to look into is two things:
1) The link you defined, needs to set additional attributes for the target page. In the "Column Link" box, you have set the link to "Page in this Application" and followed by the page number (let's say, Page 10). Below that, you should set an Item to an item on you target page (let's call that P10_PRODUCT_ID). This item should be the primary key of your detail table (on the targe page). You can select this item from the popup list. The Value of the item should be picked from a popup list as well, being the value from the record you clicked on. This should then transfer your selected item to your page. The URL will then have something like P10_PRODUCT_ID:5 at the end.
2) On the target page, 10, you must change the query slightly, so that it adds a WHERE clause:
WHERE PRODUCT_ID = :P10_PRODUCT_ID
Now, you should be set.
Hope this helps.
Borkur -
Need help with a calculated column - is there any way to reference a value in the current row?
Hey guys,
I'm a bit of a DAX newbie, and I'm running into a block. I'm creating a Power View report about IT tickets. We are going to be creating a cube to automate the data soon, I'm currently working with a flat Excel Data Table of data to demonstrate the Power
View reporting capabilities to the team. I need the default display to show the top 4-5 items basked on the Ticket Count. The three applicable columns I'm using are the TicketID, the ContactReason, and the AssetCategory - all three are
text. One slide will show the top five Contact Reasons by Ticket Count, and the other will show the top five Categories by Ticket Count. The users will see this default view, but will be able to change it to see differently ranked items or can clear the
ranking slicer altogether.
What I've accomplished so far is to create the Calculated Field [Ticket Count] = COUNTA(Table1[TicketID])
And 2 other calculated fields:
[Contact Rank] = RANKX(ALL(Table1[ContactReason]),[Ticket Count],,,DENSE)
[Asset Rank] = RANKX(ALL(Table1[AssetCategory]),[Ticket Count],,,DENSE)
If I were creating a Pivot Table, this would be great. These fields calculate everything the right way. The problem is, I need to have a Rank slicer on each slide and the calculation by itself contains no data - with no data, there's nothing to slice. I
realized I need to actually have columns of data so I can create a slicer. I need each row of the table to show the same [Contact Rank] for every instance of a particular ContactReason (and the same for the [Asset Rank] and AssetCategory).
The RANKX formulas pasted into the Calculated Column section only show a value of 1 - with no Pivot table summarizing the fields, it's counting each row's ticket once, giving every line the tied Rank of #1.
I've solved the problem in Excel by creating 2 Pivot Tables on a separate sheet that have the data field and the calculated field for ContactRason and AssetCategory. Then on my Excel Data Table, I've added two columns that do a VLOOKUP and pull over a the
Calculated Rank from each Pivot Table that match the ContactReason and AssetCategory fields. This works on the flat Excel Data Table now, but will not be a solutions when we start pulling the data from the cube (and there is no flat table).
What I think I need is an Expression for the RANKX formula that can give me, for each row, the count of all of the times a ContactReason shows up in an entire column. There's only about 100,000 lines of data and each ContactReason or AssetCategory
may show up several thousand times. But if I can get the expression to return that count, then the RANKX formula should work in the Column. If it wasn't a DAX formula, I'd use a COUNTIF and say 'Count the entire ContactReason column anytime it's equal to the
ContactReason on THIS row', but in DAX I don't know how to reference a single value in a row. I've tried the CALCULATE() formula, but it seems like the filter needs a specific value, and doesn't work on a dynamic "cell" value.
Any help would be greatly appreciated! (I hope it all makes sense!)If I've understood you correctly then the ALLEXCEPT function may be what you're after and it could be applied in a similar way to the following...
=
RANKX(
ALL(Table1),
CALCULATE(
COUNTROWS(table1),
ALLEXCEPT(Table1, Table1[ContactReason])
DENSE
If this has missed the mark, would it be possible to clarify the requirement further?
Regards,
Michael Amadi
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
Website: http://www.nimblelearn.com
Blog: http://www.nimblelearn.com/blog
Twitter: @nimblelearn -
Need help in sorting a column in classic report
Hi I am trying to create and classic report and I need to do sorting on the columns. Also I am using a select list to filter the records in the column. When I am not using the select list the sorting is working but when I am using the selcet list and select the sort option then it is showing error. Can anyone help...
Thnaks,
RikSelect lists prior to v4 will sort on the return value. In v4, it sorts on the display value (as you're probably expecting). There's nothing really for you to fix here except if it's really important, see if you can get upgraded to v4.
-
Need help in modifying the column length
Hi Experts,
I need to modify the length of a column from char(10) to char(5), but it's showing the error of:
ALTER TABLE appr_group_table MODIFY (APPR_TBLNO CHAR(5)) It's showing the below error:
ERROR at line 1:
ORA-01441: cannot decrease column length because some value is too bigI've checked in the dbase but there is no any value of this column having more than 5 characters:
SQL> SELECT APPR_TBLNO FROM appr_group_table;
APPR_TBLNO
ANTAB
ANTAB
ANTST
SCCTR
SOTAB
SOTAB
SOTAB
SOTAB
SOTAB
SOTAB
SOTAB
11 rows selected.Thnx in advance for helping me out.....char means fixed length variable. when you say char(10) oracle will reserve 10 places for your data. that means in your output what you are seeing as blank spaces are also considered as data. that is the reason, it is not allowing you to reduce the size.
better solution is to create new column with varchar2 or char(5) datatype and transfer this column data into new column and then drop original column. -
Need Help in Union of Columns in FX
Hello Experts,
In database I have a table having two columns, Version From, Version To.
Column "Version Start" data is like
V0, V1, V2, V3, V4....upto V11 (fixed value)
Column "Version End" data is like
V1, V2, V3..... upto V11 (fixed value V0 is not present)
User requirement is like create two prompts on these columns and select the data
between these two fields and see the report. This is achieved by prompt and presentation variable.
But the problem is let say user select V1 from Version Start, then Version End prompt should show all values apart from V1.
If user select V2 then it should all value in Version End apart from V2.
I tried but it seems 'union' function does not work in rpd bmm, nor in fx in OBIEE 10g.
Can you all please help.
ThanksThe easiest way to do this, and it could be done in a few minutes, would be to move to a currently supported version of Oracle, 11gR1 or 11gR2, where we have the PIVOT and UNPIVOT operators.
In the desupported version you have the best choice is to hit http://asktom.oracle.com and look up the solution he published there some years ago.
I don't have the link so you can find it as fast as I can but look under "pivot" and "crosstab." -
Need help in GROUPING of COLUMN Based Query
Hi,
I am facing problem in generating a scenario:
I have built a Query like this:
SELECT
a.sal,
a.country
FROM
employee a,
department d
WHERE
a.dept_code=b.dept_code
I want the query where the Query will produce a result set based on SALARY based on COUNTRY.
For example if the COUNTRY is US then it will show the breaking of SALARIES.If the COUNTRY is NON US it will club the SALRIES
Any help will be needful for meHi,
Here's one way:
SELECT deptno
, SUM (sal) AS sal
FROM scott.emp
GROUP BY deptno
, CASE
WHEN deptno = 30
THEN empno
END
ORDER BY deptno
;Output:
` DEPTNO SAL
10 8750
20 10875
30 1600
30 1250
30 1250
30 2850
30 1500
30 950In the table, there are 3 rows with deptno=10, and 5 rows with deptno=20, but the CASE expression returns NULL for all of them, so there is only 1 sub-group for each of those deptnos.
Edited by: Frank Kulash on Mar 13, 2013 5:41 AM
This is essentially the same solution that Jeneesh already posted. (Sorry, I didn't see that before.) -
Need help in hiding particular column of a table depending upon value
Hi experts,
I have developed a custom smartform and Print program.
My problem is ..depending upon the data i recieve,...i have to hide a particular column.
For example ... i have a table with 2 rows...one header and main row..This table has 3 column.
I have to hide one of the column depending upon the data i recieve. So my output should have 2 rows and 2 columns.
Please help.well vishwa u r right it wont work for multiple columns,
then i guess this shud work.
@thendral
U can try like this create the rows with single column
then print all ur text elements with spaces inserted manually between them with text editor then in conditions tab of the text elements specify ur condition according to what all u want to print.
кu03B1ятu03B9к -
Migrating from TSQL Need Help? printing multiple columns in Stored procedur
I need to create a Stored Procedure which returns set of columns not all
(for eg FirstName, LastName, Dept_Id) from emloyee table based on certain conditions.
In TSQL, it is very simple to create such stored procedures which return full recordset(or subset).
I tried creating explicit cursors but I can print only one record at a time. I dnt want concatenation of columns. I want seperate columns in ouput. How to achieve this.?
Code : (But i can only concatenate and print results, what i want is diffrent columns)
declare
f_name employees.first_name%type;
l_name employees.last_name%type;
cursor c is
select first_name,last_name
from employees;
begin
open c;
loop
fetch c into f_name,l_name;
exit when c%notfound;
DBMS_OUTPUT.PUT_LINE (f_name||' '||l_name);
end loop;
close c;
end;Another very informative article on ref cursors:
PL/SQL 101 : Understanding Ref Cursors -
Need help in GL table column mapping - R12.1.3
Hi,
we are upgrading from 11.5.10 to R12.1.3
While modifying one of the reports, come across a query which uses gl_mc_reporting options table.
This table is replaced by gl_ledger_relationships in R12.
However, in the query, we are using reporting_set_of_books_id in the where clause.
Can you please let me knw the corresponding column I need to use from gl_ledger_relationships in R12.
Thanks!well vishwa u r right it wont work for multiple columns,
then i guess this shud work.
@thendral
U can try like this create the rows with single column
then print all ur text elements with spaces inserted manually between them with text editor then in conditions tab of the text elements specify ur condition according to what all u want to print.
кu03B1ятu03B9к -
SQL Help -- Need help with pivoting the columns to rows
I have a requierement to split the columns into multiple rows. For example:
EMP_DEPT
rowid empid1 ename1 dept1 empid2 ename2 dep2 empid2 ename2 dep3 empid4 ename4 dept4
100001 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 10 4 SMITH 20
100002 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 20
Note: EMP_DEPT may not always have all the 4 employee info populated for example in row 2 only 3 employees info is there
I need to convert it and insert into EMPLOYEE table as follows:
EMPLOYEE
empid ename dept
1 SCOTT 10
2 DAVE 20
3 MILLER 10
4 SMITH 20
1 SCOTT 10
2 DAVE 20
3 MILLER 20
Thanks
KevFrank Thank You for your response.
I am on oracle 10gR2.
Posting some sample DDL and data here as requested:
CREATE TABLE EMP
PK NUMBER(10),
EMP_NAME1 VARCHAR2(100 BYTE),
EMP_ID1 NUMBER(10),
EMP_NAME2 VARCHAR2(100 BYTE),
EMP_ID2 NUMBER(10),
DEPT_NAME1 VARCHAR2(200 BYTE),
DEPT_ID1 NUMBER(10),
DEPT_NAME2 VARCHAR2(200 BYTE),
DEPT_ID2 NUMBER(10)
CREATE TABLE EMP_DEPT
( PK NUMBER(10),
ENTY_TYPE VARCHAR2(100),
ENTY_NAME VARCHAR2(100),
ENTY_ID NUMBER(10)
Insert into EMP
(PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1, DEPT_NAME2, DEPT_ID2)
Values
(1, 'SCOTT', 10001, 'FRANK', 10002,
'MARKETING', 10, 'ACCOUNTING', 20);
Insert into EMP
(PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1)
Values
(2, 'SCOTT1', 10003, 'FRANK1', 10004,
'MARKETING1', 30);
COMMIT;
SELECT
FROM
EMP;
PK EMP_NAME1 EMP_ID1 EMP_NAME2 EMP_ID2 DEPT_NAME1 DEPT_ID1 DEPT_NAME2 DEPT_ID2
1 SCOTT 10001 FRANK 10002 MARKETING 10 ACCOUNTING 20
2 SCOTT1 10003 FRANK1 10004 MARKETING1 30 My requirement is to:
SELECT from emp and INSERT INTO EMP_DEPT so that columns are broken into rows as follows
PK ENTY_TYPE, ENTY_NAME ENTY_ID
1 EMPLOYEE SCOTT 10001
2 EMPLOYEE FRANK 10002
3 DEPARTMENT MARKETING 10
4 DEPARTMENT ACCOUNTING 20
5 EMPLOYEE SCOTT1 10003
6 EMPLOYEE FRANK1 10004
7 DEPARTMENT MARKETING1 30 Thanks
Kevin
Edited by: user10210466 on Dec 8, 2010 1:37 PM -
Need help in updating "TIMESTAMP" column
Hi,
Below is my table description, i want to update timestamp column but i could not able to do, please help me on this.
ID VARCHAR2(4 BYTE),
TYPE VARCHAR2(1 BYTE),
DATET TIMESTAMP(6),
TYPE NUMBER
Currently i have value "5/1/2009 9:00:00.000000 AM" for DATET column, now i want to update it to "5/1/2009 9:00:00.000000 PM". Please help me out.
Thanks.Hi,
Here's one way:
UPDATE table_x
SET datet = datet + INTERVAL '12' HOUR
WHERE datet = TO_TIMESTAMP ( '01/05/2009 09:00:00'
, 'DD/MM/YYYY HH24:MI:SS' -- or whatever
); -
Need help for the query columns to rows
Hi everyone,
I have two tables TABLE1 and TABLE2; TABLE1 is Master table,TABLE2 is child table.
The key for TABLE1 is C1 column
The key for TABLE2 is C1,C_MONTH Columns
The sample data is as follows
TABLE1
======
C1 C2
1 A
2 B
3 C
4 D
TABLE2
======
C1 C_MONTH C3
1 JAN AAA
1 FEB BBB
1 MAR CCC
1 APR DDD
2 JAN ZZZ
2 FEB YYY
2 MAR XXX
2 APR UUU
I want to display the data as follows
1 A JAN AAA FEB BBB MAR CCC APR DDD
2 B JAN ZZZ FEB YYY MAR XXX APR UUU
Can any one help me how to write this query?
Thanks in advance[email protected] wrote:
Thanks for the update
but I want the out put as column values rather than one column as follows
C1 C2 J_MONTH J_VALUE F_MONTH F_VALUE M_MONTH M_VALUE A_MONTH A_VALUE
1 A JAN AAA FEB BBB MAR CCC APR DDD
2 B JAN ZZZ FEB YYY MAR XXX APR UUUThis is a standard pivot.
In 10g or below you can do something like...
SQL> ed
Wrote file afiedt.buf
1 with table1 as (
2 select 1 c1, 'A' c2 from dual union all
3 select 2, 'B' from dual union all
4 select 3, 'C' from dual union all
5 select 4, 'D' from dual
6 ),
7 table2 as (
8 select 1 c1, 'JAN' C_MONTH,'AAA' C3 from dual union all
9 select 1,'FEB','BBB' C3 from dual union all
10 select 1,'MAR','CCC' C3 from dual union all
11 select 1,'APR','DDD' C3 from dual union all
12 select 2,'JAN','ZZZ' C3 from dual union all
13 select 2,'FEB','YYY' C3 from dual union all
14 select 2,'MAR','XXX' C3 from dual union all
15 select 2,'APR','UUU' C3 from dual
16 )
17 -- end of test data
18 select table1.c1, table1.c2
19 ,max(decode(c_month, 'JAN', c_month)) as jan_month
20 ,max(decode(c_month, 'JAN', c3)) as jan_value
21 ,max(decode(c_month, 'FEB', c_month)) as feb_month
22 ,max(decode(c_month, 'FEB', c3)) as feb_value
23 ,max(decode(c_month, 'MAR', c_month)) as mar_month
24 ,max(decode(c_month, 'MAR', c3)) as mar_value
25 ,max(decode(c_month, 'APR', c_month)) as apr_month
26 ,max(decode(c_month, 'APR', c3)) as apr_value
27 from table1 join table2 on (table1.c1 = table2.c1)
28* group by table1.c1, table1.c2
SQL> /
C1 C JAN JAN FEB FEB MAR MAR APR APR
1 A JAN AAA FEB BBB MAR CCC APR DDD
2 B JAN ZZZ FEB YYY MAR XXX APR UUU
SQL>From 11g upwards you can use the new PIVOT keyword.
Maybe you are looking for
-
I can't sync music from iTunes Library to iPhone
I've just set up my iPhone and whilst the iPhone syncs all my email, calendars etc, it doesn't sync with the music already in my Library. I've tried manually syncing but a 'no entry' sign comes up. I've unchecked all the music, tried almost everythin
-
I have a MBP running Yosemite. My partner has a MBAir running OSX 10.8.5 (M-Lion?) He needs to use some medieval characters in his writing as a grad student in ENglish. On both machines, we installed the Unicde Hex Input source and selected it. On m
-
Compilation problem with lib32-wxgtk
Hi, when I try to compile lib32-wxgtk I get this error: checking for GTK+ - version >= 2.0.0... *** 'pkg-config --modversion gtk+-2.0' returned 2.24.14, but GTK+ (2.24.13) *** was found! If pkg-config was correct, then it is best *** to remove the ol
-
Program related ENHANCEMENT-POINT/SECTION with the name LMEPOF8D_02 exists
Hello In an upgrade, after finishing with the SPAU task we got the following error in the standard object LMEPOF8D: A program related ENHANCEMENT-POINT/SECTION with the name "LMEPOF8D_02" already exists. Anyone knows which cause could be generate thi
-
Hi, actuallly the requirement suppress out put for closed po. when delivery completed and final invoice indicator is checked the output shouldnt take place. po out put should be suppress. The following fields needs to be cleared to suppress PO outpu