Get a Column value based on other column value in a single query
Hi All,
I have a problem here -
In Table XYZ I have columns by name A, B, C and COL_I. COL_I has a value A or B or C. Based on the value in COL_I, I need to get the value from the corresponding column in the table.
For Ex: If the COL_I has the value as 'A' then I need to fetch the value from the column A. If it is 'B' then fetch from column B.
This has to be done in a single query.
Thanks,
san_mah
Hi You can use this query
I have taken this simple case
SQL> desc column_fetch
Name Null? Type
C_FIRST_NAME VARCHAR2(30)
C_MIDDLE_NAME VARCHAR2(30)
C_LAST_NAME VARCHAR2(30)
C_GET_NAME VARCHAR2(30)
based on C_GET_NAME find values in columns C_FIRST_NAME,C_MIDDLE_NAME,C_LAST_NAME
Values in Table
SQL> select * from column_fetch
2 ;
C_FIRST_NAME C_MIDDLE_NAME C_LAST_NAME C_GET_NAME
A B C D
A B C F
A B C F
A B C A
A B C B
A B C C
CASE Statement:
SELECT
CASE WHEN c_first_name=c_get_name THEN c_first_name
WHEN C_MIDDLE_NAME=C_GET_NAME THEN C_MIDDLE_NAME
WHEN C_LAST_NAME=C_GET_NAME THEN C_LAST_NAME
ELSE 'Nothing' END
FROM column_fetch;
Similar Messages
-
Render a column based on other column value in the same table
JDev 11.1.1.6.0
This may be a silly question but I am stuck
I need to conditionally render a column say A. Condition is like if the value in the other column B of same table is equal to F. I should render column A only when this condition is satisfied. I have tried the following code:
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146"
rendered="#{row.PhoneNumber1ResponseFlag eq 'F'}">
<af:outputText value="#{row.PhoneNumber1}"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80" rendered="true">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
The data shown in the table for column PhoneNumber1ResponseFlag is F. Still my condition is not working.Timo was saying that it is not possible to render the column in some situations and not in anothers, you will always have to render the column.
The best way to do this is instead of showing a column with the text ' ', show something meaningfull to the user. This is a DataWarehouse advice to you and may be usefull since you're using ADF in a area that uses DataWarehouse..
So the code could be something like this (based on Timo's code):
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146">
<af:outputText value="#{row.PhoneNumber1ResponseFlag eq 'False.' ? row.PhoneNumber1 : 'No value applied.'"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
Hope that helps,
Frederico. -
How to make column range based on a column in Oracle BI 11g
Hello everyone!
I want to know, how to make column range from a column in oracle bi 11g.
for example!
I have a column amounts and I want to build on this with other values of quantity, other column range 1-9,10-49,50-99,100-249, 249 o more.
regards!
when I try to make the range I have error.
Syntax error [nQSError: 26012] . (HY000)
SQL Issued: SELECT CASE WHEN "CUBO_DEEE_TAB"."CANTIDAD" BETWEEN 1 AND 9 THEN 1 a 9 ELSE "CUBO_DEEE_TAB"."CANTIDAD" END FROM "DM_DEEE"
Edited by: 964157 on 09-oct-2012 11:50You cannot add columns dynamically. But you can define a maximum number of numbers and then hide unused columns in your form useing SET_ITEM_PROPERTY(..,VISIBLE, PROPERTY_FALSE);
-
How can I delete a column of numbers that are referenced in another column without deleting the other column?
select the column to delect by click in the column header
select the contextual menu for that column by clicking (and holding) the down arrow:
select "Delete Column" to remove the column: -
Need to filter unique columns based on other column's values
I'm rookie and I'm running this query:
SELECT TO_NUMBER (hs_key) bug, "HS_TABLE_NAME", "HS_COLUMN_NAME",
"HS_CHANGE_DATE", "HS_CHANGE_TIME", "HS_CHANGER", "HS_NEW_VALUE"
FROM cb_tdqatodo1_history
WHERE (hs_column_name) = 'BG_STATUS'
AND (hs_new_value) LIKE '%Not a Bug'
AND (hs_change_date, hs_key) IN (
SELECT MAX (hs_change_date) hs_change_date,
hs_key
FROM cb_tdqatodo1_history
GROUP BY hs_key);
The result is
BUG HS_TABLE_NAME HS_COLUMN_NAME HS_CHANGE_DATE HS_CHANGE_TIME HS_CHANGER HS_NEW_VALUE
101 BUG BG_STATUS 12/16/2005 17:49:54 helpdesk Closed Not a Bug
101 BUG BG_STATUS 12/16/2005 12:20:22 hgarcia Not a Bug
1012 BUG BG_STATUS 1/21/2005 08:04:56 helpdesk Not a Bug
1014 BUG BG_STATUS 2/1/2005 14:33:56 lossa Not a Bug
1020 BUG BG_STATUS 1/28/2005 17:04:45 fgonzalez Not a Bug
I need to resolve the cases when the field BUG has the same value in HS_CHANGE_DATE but different value in HS_CHANGE_TIME without impact the rest of the records?
In this case I need the result just show me one Bug per line.
ThanksBasically you want to create two filters on different columns and have OR clause between them instead of an AND. To acheive this, add both of your filters, once added you will the them in the filters section. Click on AND, and it will change to OR. This should solve your problem.
Look at the below image where you can see two filters with an AND clause. Clicking on AND will change it into OR.
http://gerardnico.com/wiki/_media/dat/obiee/presentation_service/obiee_filters.jpg
Close thread and award points please.
Thanks,
-Amith. -
How to fetch the Alias column values based on different column values?
Hello Gurus,
I have a table with the following struture -
"drop table T;
create table T(Name, Symbol, Amount,dep) as select
'Anderia', 'AA', 1050000,'HR' from dual union all select
'Michael', 'ML',150000,'Sales' from DUAL union all select
'Bill', 'BL', 1050000,'Finance' from dual union all select
'Nancy', 'NY', 4000,'HR' from DUAL union all select
'Anderia', 'AA',3000,'HR' from dual union all select
'Michael', 'ML',1050000,'Sales' from DUAL union all select
'Bill', 'BL', 1200000,'Finance' from DUAL union all select
'Anderia', 'AA', 1200000,'HR' from DUAL union all select
'Vish', 'VH', 1200000,'Marketing' from DUAL;"Ans try to find out the values of the column like
Name,symbol,dep,Amount,%Total,$Cumm Total, Rank but some additional columns like -
HR Amount, %HRTotal,$HR Cumm Total,
Finance Amount, %FinanceTotal,$Finance Cumm Total
Sales Amount, %SalesTotal,$Sales Cumm Total,
Marketing Amount, %MarketingTotal,$Marketing Cumm Total
then i am using the following query to fetch the Name,symbol,dep,Amount,%Total,$Cumm Total, Rank columns -
select name
, decode(grouping(symbol), 0, symbol, 'Total') symbol
, dep
, sum(amount) amount
, sum(per_total) "% Total"
, decode(grouping(symbol), 0, max(Cum_per_total), null) "% Cumm Total"
, decode(grouping(symbol), 0, max(rank), null) rank
from (
select name
, symbol
, dep
, amount
, per_total
, sum(per_total) over(order by rk) cum_per_total
, rank
, rk
from (
select name
, symbol
, dep
, sum(amount) amount
, round((sum(amount)/max(total_amount)) * 100,2) per_total
, dense_rank () over (order by sum(amount) desc) as rank
, row_number() over(order by sum(amount) desc) as rk
from (
select name
, symbol
, amount
, dep
, sum(amount) over() total_amount
, sum(amount) over ()
from t
group
by name, symbol, dep
group
by grouping sets((name, symbol, dep), ())
order by rank, max(rk) nulls lastBut i want to fetch the following columns as well.......how can i do it?-
HR Amount, %HRTotal,$HR Cumm Total,
Finance Amount, %FinanceTotal,$Finance Cumm Total
Sales Amount, %SalesTotal,$Sales Cumm Total,
Marketing Amount, %MarketingTotal,$Marketing Cumm Total
as i want all of the records, then going to specific to the dep.....do i need to use the case here?
Thanks for all of your time and effort in advanceHello Frank Kulash/Łukasz Mastaler,
Thanks for your time and effort.
I am using the Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
I am looking forward to have some additional columns (column alias) along with the the returned by the mentioned query - which are named as -
1- HR Amount
2- %HRTotal
3- %HR Cumm Total
4- Finance Amount
5- %FinanceTotal
6- %Finance Cumm Total
7- Sales Amount
8- %SalesTotal
9- %Sales Cumm Total
10 -Marketing Amount
11- %MarketingTotal
12- %Marketing Cumm Total
based on the logic like -
HR Amount = sum of amount case dep ='HR'
%HR Total = % of amount case dep ='HR'
%HR Cumm Total (cumulative % based on the cumulative total of %HR Total) = Cumm % of amount case dep ='HR'
similarly rest of the column........
Now how do i use case with a logic so that it returns me the columns as i want them ...using the above mentioned query .......
Kindly help me .....thanks in advance for all of your time -
Looping thru column names based on a variable value
I have an ArrayCollection with a series of columns named
price1, price2... thru to price10
I'm trying to loop thru these columns based on a variable
value, but can't figure the syntax:
for (var column:int = 1; column < 11; column++){
testPrice = myGrid.selectedItem.price(column); <-- this
doesn't work
}Try testPrice = myGrid.selectedItem["price" + column];
Remember to test that selectedItem isn't null before you try
to assign the values.
TS -
Programatically Assigning Column Value Based on Another Column
I have a problem as follows:
My database table has the following setup:
There may be many gift numbers the same, however many different recipient numbers for each gift.
The receipient number should increment from 1-X based on the gift number, for example, if the gift number is the same then the receipient number should increment for that gift.
Gift Number
Recipient Number
1
1
1
2
1
3
2
1
3
1
3
2
The programmatic code for inserting a new row would be:
Check if gift number already exsists in database.
-if it does exsist then find latest and increment current receipient number by one for receipment number
-if it does not exsit set receipient number at 1
How do i do this?
JDEV - 11.1.2.4 (ADF BC)Your use case has some flaws which you should think about before trying to implement it.
1) think about what happens if multiple users try to insert a record at the same time. What can happen? How do you want to handle this situation?
2) do you really need the number to be gap less? The use case can be implemented easily if you don't have this restriction.
3) The table should have the technical primary key to avoid pk clashes due to multiple inserts at one time.
Now, if you have a technical pk as primary key, you can setup a unique key on both of the other columns which prevents that somehow you get duplicates there.
You let the user insert the gift number and calculate the recipient number as max(recipient number)+1. Then you commit the record. If you don't get an error you are finished, if you get an error you add 1 to the recipient number and try to commit again, until the insert works.
Timo -
How to re-calculate a column value based on another column value in the same ADF Table row
Hi,
I'm using Jdeveloper 11.1.2.3.0.
I have an adf table with 2 columns, columnA and columnB.
When the value changed in ColumnA,
1) i need to call a PLSQL and update the ColumnB value that is returned from PLSQL.
2) Show a warning message if the existing value in ColumnB is different from the one that is returned from PLSQL.
Can anybody suggest how can i accomplish this?
Thanks,
Vinodhi user,
if you have inputtext means have a valuechangelistener
in that call your pl/sql function supply input value to the appropriate function then grab the result of the function. then bind the column inputtext and compare with it. then raise your warning using FacesMessage classes.
Sameh Nassar: Create PL/SQL Function And Call It From Your ADF Application -
How to insert into date column based on other columns?
Hi
I have four columns in a table called game named as
R_Day - Type - Number
R_Month - Type - Number
R_Year - Type - Number
R_Date - Type - Date
I have around 1000 records and i want to fill R_Date column based on the data in the R_Day,R_Month,R_Year.
How to write a query to fill the R_Date column based on other three columns.
Thanks
srinivasselect
to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
dt from (select 23 R_Day,07 R_Month,2007 R_Year from
dual);
Hi,
Update <Table Name> set R_Date=select
to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
from <Table Name>
Regds.
Nirmal
SQL> select * from test;
R_DAY R_MONTH R_YEAR R_DATE
1 1 2007
21 11 2007
SQL> update test
2 set r_date = select to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
3 from test;
set r_date = select to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
ERROR at line 2:
ORA-00936: missing expression
SQL> update test
2 set r_date = to_date(r_day||'-'||r_month||'-'||r_year,'dd-mm-yyyy');
2 rows updated.
SQL> select * from test;
R_DAY R_MONTH R_YEAR R_DATE
1 1 2007 01-JAN-07
21 11 2007 21-NOV-07
NB:Please test before posting.. -
How to update a column with different values but all other row values r sam
Hi,
I have a table like this.
Col1 col2 col3 col4
10 20 30
10 20 30
10 20 30
i need to update col4 with different values coming from other table like this
Col1 col2 col3 col4
10 20 30 xxxx
10 20 30 yyyy
10 20 30 zzzz
how can i update the table. pls let me know how to use the where condition in the update stmt.
thanks,
jay
Edited by: user2558790 on Nov 20, 2009 12:26 PMwhat is the logic for this kind of update...????
Greetings,
Sim -
Fill DDL based on other field values in offline interactive adobe form
Hi,
I have a requirement where in i need to fill the values for a dropdown list based on 3 other field values in offline adobe interactive forms which uses web service to interact with SAP.
Note: I read many blogs and posts in SDN , but couldn get much info ab the same, so posting a new thread.
Thank you.
Regards,
SoumyaHi Soumya,
It is possible but a little bit tough and will make your form heavier.
The solution is advisable only when there is not very much data required for the drop down(May be not more than 500 values as it will create performance issue).
You can create a hidden table on the form contaning data for all the combinations. Depending on the selection of another 3 fields you can write the code to select only those values from this hidden table which are applicable to that selection. These values you can add to the drop down list removing the previous values.
Only you have to do is on calculate or vlaidate event of target DDL you have to write your code.
Pseudocode:
1. Clear your DDL using deleteItem() method.
2. Loop at your hidden table.
3. Inside the loop check for applicable entries depending on selection in other 3 fields.
4. Select the appropriate vlaues
5. Add using additem method().
Refer formCalc or JavaScript help for the appropriate code.
Hope this will be helpfull.
Regards,
Vaibhav -
How to add a new column in between two other columns
I need to add a new column in between two other existing columns. Does anyone know how to do that? The ALTER statement adds the column at the end. Can someone give an example.
Thanks
Murali
nullThere is no simpler way of doing this because it is not strictly necessary: you can always see your data in the order you want simply by going SELECT col1, col2, col98, col4, etc. Thus the column order only matters when you execute SELECT * FROM...
If that really is important enough to you you'll have to drop and re-create the table, for which there are a number of different strategies.
Your final comment suggests that you don't retain your database build scripts. If you did then rebuilding your constraints would be painless. There is a lesson there. The good news is that if you have TOAD (download from www.quest.com) you can generate DDL scripts from your existing schema.
HTH, APC -
Field to be populated based on other two values
I have a two fields from and to
From value is AB000000121 and To value is AB000001200
I have a third field quantity i need the range between the above two values to be displayed automatically
How can we do thisFor me the question is what is the range between the tow values? They are not numbers, integers or longs.
The only solution I see is to implement a bean method which calculates the range (you have to do this yourself) and return the correct number or store it in a bean property.
This you can use in a EL to show the result.
Timo -
Unable to filter LookupSet values based on another Lookup value
Hey all, I've got a report item where I'm pulling a list of values using a lookupset. The lookupset is working as expected, however I need to filter those results based on a different value which belongs to the same dataset as the lookup value. I'm trying
to filter on the tablix but nothing I try is working to filter. I just end up with no data when I know I should be getting one value. I tried filtering using a lookup and lookupset expression but that doesn't seem to be what is needed. This is my first time
really diving into lookups so any help would be appreciated.
Thanks,
Bryan
(using report builder 3.0)Do you only want the values where type = "Writing Assignment 1". If that is the case then modify your LookupSet as follows:
=Join(Lookupset(Fields!identifier.Value+"Writing
Assignment 1",Fields!Student.Value+Fields!value.Value,
Fields!value.Value, "Comments"), vbCrLf)
This will require that identifier matches student and type matches "Writing Assignment 1".
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek.
Maybe you are looking for
-
Filter problem with operating system in french
Hello, There is a problem with the "Operating System - Windows" filter in the french version of ZCC. If you create a bundle and go into "Requirements" and add a filter with Operating system and you set it to "Version 6.1 - Windows 7 / Windows Server
-
pls help me out as i have all my contacts and important info on my iPhone
-
An album I have previously bought songs off of is no longer available on iTunes?
I bought multple songs off of an album a few months ago and now it is no longer available on iTunes. Is this temporary thing or is the album permanently unavailable?
-
I use excel at work. Should I use Numbers or buy Office for Mac?
I use simple spreadsheets that I change the values in daily. My main concern is compatibility. I use a Macbook Air mid 2013.
-
Gentlemen I used to Garbage remover with Adobe Premiere to remove certain parts or the video clip, I tried to use the pen toon and created 5 or6 dots and connected them all but all i see is gree area Basically How do I do the job of Garbage remover