Using CASE to return a set of columns

Good day all,
Many times I have used the CASE construct to return a value based on a set of conditions but now I have a need to return a set of columns based on a set of condition.
Look at this
A
=====
id
name
account
zip_code
status
B
=====
id
name
account
zip_code
C
=======
id
name
account
zip_code
D
======
id
name
account
zip_code
I want a query that would return
id - of A
name, - of A
beneficiary, - name column of either, A, B, C or D depending on the value of A's status (A, B, C, D)
account, - account column of either, A, B, C or D depending on the value of A's status (A, B, C, D)
zip_code - zip_code column of either, A, B, C or D depending on the value of A's status (A, B, C, D)
Can anyone help with construct that could achieve this with queries only. I don't feel like this warrants PLSQL.
regards

Hi,
Is this what youa re looking for?
As Frank has said not sure what is the relationship between your tables and what Output you expect.
Sample Data used.Avoid using reserved words for column like ID and NAME
create table a (id1 varchar2(10),name1 varchar2(10),account1 varchar2(10),zip_code varchar2(10),status varchar2(10))
create table b (id1 varchar2(10),name1 varchar2(10),account1 varchar2(10),zip_code varchar2(10))
create table c (id1 varchar2(10),name1 varchar2(10),account1 varchar2(10),zip_code varchar2(10))
create table d (id1 varchar2(50),name1 varchar2(50),account1 varchar2(50),zip_code varchar2(50))
insert into A values (0, 'michael', '000000', '213401', 'A');
insert into A values (1, 'johnson', '63423', '093401', 'B');
insert into A values (2, 'fred', '23221', '203901', 'D');
insert into B values (1, 'brother', '1129812', '093083');
insert into B values (2, 'stuggard', '0093732', '087366');
insert into B values (3, 'jekins', '9009387', '329838');
insert into C values (1, 'mary', '009300', '093083');
insert into C values (2, 'lori', '112212', '654032');
insert into C values (3, 'helen', '909083', '938292');
insert into D values (1, 'mother & father', '093291', '329232');
insert into D values (2, 'Uncles & Aunties', '098762', '742326');
insert into D values (3, 'Grannies', '237643', '864433');
Query
select 
case when a.status='A' then
a.id1
when a.status='B' then
b.id1
when a.status='C' then
c.id1
when a.status='D' then
d.id1
end ID1,
case when a.status='A' then
a.name1
when a.status='B' then
b.name1
when a.status='C' then
c.name1
when a.status='D' then
d.name1
end ID1
,case when a.status='A' then
a.account1
when a.status='B' then
b.account1
when a.status='C' then
c.account1
when a.status='D' then
d.account1
end account1,
a.status status,
case when a.status='A' then
a.zip_code
when a.status='B' then
b.zip_code
when a.status='C' then
c.zip_code
when a.status='D' then
d.zip_code
end zip_code
from a ,b,c,d
where a.id1=b.id1 and b.id1=c.id1 and c.id1=d.id1Cheers!!!
Bhushan

Similar Messages

  • Update some columns using case....

    Hi ,
    Is it possible to update some columns using case statement...????
    For example when col1 is null then update to a value 'x' else update it to the value '*' , when col2 is null then update to a value y else update it to compute the running total up to that time....
    This update statement is contained in db packaged procedure and it receives the values...as parameters....
    How can i write down this update statement...?????
    Many thanks,
    Simon

    Hi ,
    Cant' it be used for two or more columns that have to be updated....????
    i mean
    update table set col_a = case when col_a is null then col_a else '*',
                       col_b = case when col_b is null then col_b else col_b+col_b_var
      end
      where .....The above in bold is running total.... This update is defined in a procedure and it receives numbers as parameters, so the need is to add them for every record it receives...., that's why i set above col_b+col_b_var... where col_b_var is the parameter of the procedure....
    SORRY...IT IS POSSIBLE.....
    Thanks , a lot
    Simon
    Message was edited by:
    sgalaxy

  • How to use, Case function and Filter in Column Formula?

    Hello All,
    I am using case function and also would like to filter value to populate.
    Below is showing error :
    case
    when '@{Time}' = 'Year' then "Time"."Fiscal Year"
    when '@{Time}' = 'Quarter' then "Time"."Fiscal Quarter"
    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')
    else ifnull('@{Time}','Selection Failed') end
    Thanks, AK

    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')I dont think Filter this works here or any other data types except number.
    Try to use option Column's->Filter->Advanced->Convert this filter to SQL
    If helps mark

  • Use session state values to set column value during insert/update

    I am building an APEX 4.2 application that uses the canned Data Loading control to upload csv data to a table.  I have modified the 'Select Data Source' page of the workflow and it now contains three LOV's that the user selects values from.  The selected values are stored in Session State.  As I'm new to APEX, I do not know how to reference Session State objects in the context of the Data Loading workflow so that the appropriate columns are set with the correct values.  My assumption is that the columns that are apart of the insert statement reside in a collection somewhere.  I just don't know how to loop through the collection, determine the correct column, and then set that column's value equal to the corresponding LOV value in Session State.

    Scott,
    This is in version 2.2.1 and there are no caching features available.
    The application does require login.
    I'm playing around with the APP_UNIQUE_PAGE_ID right now but I am finding that even in the builder if I edit the attributes of a report column and then try to edit another column it will bring up the last column I edited. Even if I use the record navigation buttons next to the Apply Changes button it will keep bringing me the same page over and over unless I constantly refresh the pages.
    Greg

  • How to use stored procedure which returns result set in OBIEE

    Hi,
    I hav one stored procedure (one parameter) which returns a result set. Can we use this stored procedure in OBIEE? If so, how we hav to use.
    I know we hav the Evaluate function but not sure whether I can use for my SP which returns result set. Is there any other way where I can use my SP?
    Pls help me in solving this.
    Thanks

    Hi Radha,
    If you want to cache the results in the Oracle BI Server, you should check that option. When you run a query the Oracle BI Server will get its results from the cache, based on the persistence time you define. If the cache is expired, the Oracle BI Server will go to the database to get the results.
    If you want to use caching, you should enable caching in the nqsconfig.ini file.
    Cheers,
    Daan Bakboord

  • How to return a set of data  by using webservice ?

    Hi.
    I am finding how to return a set of data by using java webservice that serves clients written by others such as VB. Net. Please help me !
    Thanks in advance.

    Check the how to on Accessing Oracle9iAS Java Web Service from a .NET Client
    http://otn.oracle.com/sample_code/tech/java/codesnippet/webservices/index.html
    Chandar

  • ALV grid, prevent return to line 1 column 1 after using filter button

    How can I prevent the ALV grid display from returning to line 1, column 1, after a user has modified the display using the filter or sort button ?  I know this is possible using the is_stable field when control is passed to my ALV code, but when the automatic on-screen buttons are used I can't find a way of controlling how the screen is displayed.

    Max,
    Thanks, the AFTER_USER_COMMAND event allows me access after the filter or sort button has bee npressed, but I am unable to prevent the grid from reverting to column1 line1.  By using the method GET_CURRENT_CELL I can find out the column, but it does not return me the row.   I have tried putting this column id into  SET_CURRENT_CELL_VIA_ID, as suggested by Naimesh above, and calling this from the AFTER_USER_COMMAND method, but it does not effect how the grid displays.    
    Any further advice would be very welcome.

  • How to use Special value set with Column clause to display addtional column

    hi
    can anyone tell me
    How to use Special value set with Column clause to display addtional column
    how can i use FND POPID and with COLUMN clause ?

    Dear Yaseen,
                To get the value in formula cumulative,after you have created the formula for that particular key figure,go to edit and click on tab "calculations".
    In that select overall result as 'count all values not equal to zero' and single result as 'count all values not equal to zero' .
    And mark the cumulative check box underneath.
    I hope you get the desired result and please do me favour .
    Sumit goomber

  • How to set unequal columns using master pages in InDesign CS3?

    How to set unequal columns using master pages in InDesign CS3?

    I don't have CS3 anymore but I don't think this has substantially changed in the last few versions of InDesign.
    Choose View > Grids & Guides > uncheck Lock Column Guides. Then drag the column guides to the position you want.

  • Is it possible to set default column widths in list view when using a finder window in Mavericks?

    The default 'document' column is way too wide and forces you eye to track all the way across the screen to read info like "date modified', 'kind' or 'size'.
    Tried several times to create a narrower default 'document name' column with no results. Couldn't find anything in preferences or view options. Tried dragging column headers while holding the down the option key with no results. 
    Every time I open a new finder window, all columns except the 'document' column affixed to the right side of the window. Also, when you grab the bottom right corner of a window to resize smaller, the lists become re-affixed to the right side of the window when opening the window back up.
    Experiencing the same problem in Mavericks 10.9.3 on an iMac and Macbook Pro Retina.
    Thanks if you've made it this far:)

    This was a great place for me to start
    Thank you
    I took profdant139's suggestions a bit further as my real goal was to have the "Document column" narrower. The goal to be able to see all the other document info that was usually hidden way out to the right
    To achieve my results I right clicked in the upper bar with the column names and chose from the drop down box "comments" column (as suggested). I then dragged it to the far right. This pushed all the other columns over.
    In the end of the day I ended up adding "Size" and "Date modified" columns as well to get my desired results.
    Remember one can move different columns around to be in the order you need by clicking on the column to get it active and then left click and drag it to where you want
    Another great thing is that by default (Using Mavericks) the date modified, opened,created columns have date and time. One can shrink them down to xx/xx/xx format by manually adjusting the column width like one does in Excel - click on column separator up top and drag
    Once all that is done, at least on my box, I closed it out and opened up a new finder window and everything was as I wanted.
    Thank you for the help  from the above helper to get me here

  • Set the column order in document library using power shell

    hi all,
     am looking for a power shell script which set the column order in the document  library, when i try to upload a  document.
     ie; i am  uploading a  doc to the doc lib. which has the below columns:
     columnA -   [choice field  - mandatory ]
     columnB -   [lookup field  - mandatory ]
     columnC -   [single line of text  - optional ]
     columnD -   [choice field  - optional ]
     columnE -   [choice field  - mandatory ]
    now when  the end user uploads a   document in my doc lib, i would like to see the mandatory columns takes up the top order and then optional fields.
     columnA
     columnB
     columnE
     columnC
     columnD
    so, is there any script, through which i can set the mandatory columns which will be coming in top and the optional fields as next order

    This is sample PowerShell code to reorder fields in a content type of a list.
    $web = Get-SPWeb http://aissp2013/sites/TestSite
    $list = $web.Lists["MyList"]
    $contentType = $list.ContentTypes | where {$_.Name –eq "MyTestCT"}
    $ctArray = "Title","ColumnA","ColumnB","ColumnD","ColumnC"
    $contentType.FieldLinks.Reorder($ctArray)
    $contentType.Update()
    Blog | SharePoint Learnings CodePlex Tools |
    Export Version History To Excel |
    Autocomplete Lookup Field

  • Credit Note in case of return scenario

    Hi,
    In case of return scenario, credit note is issued with reference to return order or return delivery?
    I am unable to see the copy control setting in IDES for RE(Return Order) to G2(Credit Memo).
    Could any one please let me know the setting for the same (Header and item).
    Regards
    Suman

    Hi Suman,
                 As for the standard in the IDES,the Credit memo will be created with reference to the Creditmemeo request because of that RE to G2 copy control setting may not avail.
    You copy the settings same as Creditmemo request(CR) to Credit memo (G2), You just change the name CR in to RE it will work.
    -->Other wise you can use Credit for returns RE document type to create credit memo for return order RE for this copy control avail in the IDES t.code VTFA.
    I hope it will help you
    Regards,
    Murali.
    Edited by: Murali Mohan.T on Feb 27, 2008 11:07 AM

  • Can I use the value returned from a Text Function in another Formula?

    I'm writing a report in Hyperion System 9 BI + Financial Reporting Studio version 9.2. I have 2 grids in my report.
    Grid1 Column A is set up as a text function using the function type - <<GetCell("Grid2", 1, a, 1)>>. I would like to use the values returned from this text function in Column A (Grid 1) in a formula in Column B (Grid 1).
    Is it possible to use the values returned in Column A of the text function in another formula? My report does not seem to recognize Column A as numerical values, even though the values to be returned are numerical.
    If so, how do I recognize the values in Column A Grid 1 as numerical values and not text?
    Thanks for any help you can offer!

    Hi Edson,
    Yes you need to use the CALC_ERROR macro function to be able to test whether the last macro function returned an error. CALC_ERROR will return an 'X' if there an error occured during the execution of the last macro function.
    You can use a macro similar to the following:
    IF
      CALC_ERROR( )
      = 'X'
          DO SOMETHING HERE
    ENDIF
    Let me explain how this works internally. The SAP system maintains a global variable g_flg_calc_error during the execution of macros in the planning book. The g_flg_calc_error variable will contain the value of f_calc_error that was set by the last macro function which executed. The ABAP coding of a planning book is something like this:
    data: g_flg_calc_error type /SAPAPO/FLAG.
    * SAP will pass g_flg_calc_error variable to all macro
    * functions. When SAP calls a macro function, it does
    * something like this.
    call function '/SAPAPO/MACRO_FUNCTION_HERE'
            exporting
              plob_values      = i_s_adv_plob_values
              sdp_book         = g_c_advf_sdp_book
              sdp_view         = g_c_advf_sdp_view
            tables
              cols_index       = i_t_cols
              value_tab        = l_t_value_tab
            changing
              f_calc_error     = g_flg_calc_error
    As you can see, the g_flg_calc_error variable
    is passed in the "changing" part of the call. The macro  function being called can then use the f_calc_error
    variable to change the value of the global
    g_flg_calc_error variable. In fact, the macro function being called can also check (by looking at the f_calc_error variable) if the last macro function reported an error.  The CALC_ERROR macro function just checks the value of f_calc_error parameter (w/c in fact is the value of the g_flg_calc_error variable) and returns "true/X" if the f_calc_error was set to true by the last macro function.
    Hope this helps in clearing things out

  • How to clear alert when a null value is returned for a metric column?

    Hey all,
    Recently, I've encountered a problem about clearing alert when a null value is returned for a metric column. From Oracle official doc, it seems that NO_CLEAR_ON_NULL could be used for this propose. However, it doesn't.
    Here is the line from doc, you can see when NO_CLEAR_ON_NULL is set as FALSE, the null value will clear alert, and the default value for NO_CLEAR_ON_NULL is FALSE.
    NO_CLEAR_ON_NULL: This attribute is used to control severity clearing when a null value is returned for a metric column. It defaults to FALSE with the behavior that a null value ends up clearing previous alert severities. With a TRUE value for this attribute, null values will be skipped in severity evaluations without clearing the severity.
    TRUE | FALSE (default)
    STATELESS_ALERTS: This attribute if set to TRUE indicates to EM that alerts on this
    column will not have corresponding clears. This allows the UI to decide whether to
    allow users to manually clear alerts on this column.
    TRUE | FALSE (default)Here is my code for the metric,
    -- meta definition
      <Metric NAME="Flushing_Table_Overtime" TYPE="TABLE" HELP="NO_HELP">
        <Display>
          <Label NLSID="mmd_ip">Flushing Table Overtime</Label>
        </Display>
        <TableDescriptor>
          <ColumnDescriptor NAME="State" TYPE="STRING" IS_KEY="FALSE">
            <Display>
              <Label NLSID="mmd_rc_State">State</Label>
            </Display>
          </ColumnDescriptor>
          <ColumnDescriptor NAME="Time_Seconds" TYPE="NUMBER" IS_KEY="FALSE">
            <Display>
              <Label NLSID="mmd_fto_Time_Seconds">Flush Table consume Seconds</Label>
            </Display>
          </ColumnDescriptor>
        </TableDescriptor>
        <ExecutionDescriptor>
          <GetTable NAME="MysqlProcessAggregate"/>
          <GetView NAME="v_flushing_tables" FROM_TABLE="MysqlProcessAggregate">
            <Column NAME="State" />
            <Column NAME="Time_Seconds" />
            <Filter COLUMN_NAME="State" OPERATOR="EQ">Flushing tables</Filter>
          </GetView>
        </ExecutionDescriptor>
      </Metric> 
    -- coll definition
      <CollectionItem NAME="Flushing_Table_Overtime">
        <Schedule>
          <IntervalSchedule INTERVAL="10" TIME_UNIT="Min" />
        </Schedule>
        <MetricColl NAME="Flushing_Table_Overtime">
          <Condition COLUMN_NAME="Time_Seconds"
                     CRITICAL="30" OPERATOR="GT"
                     MESSAGE="There is a Flushing Table command has exceeded %critical_threshold% seconds."
                     MESSAGE_NLSID="msg_Flushing_Table_Overtime" />
        </MetricColl>
      </CollectionItem>If this feature can not be achieved by coding XML, then is there a way to clear alert with Oracle Package? I have confirm neither sysman.em_severity.delete_current_severity nor sysman.em_severity.clear_alerts could do it.
    Would anyone give me a hint?
    Thanks in advance!
    Best wishes,
    Satine

    > I am executing in this manner
    var RESULT BOOLEAN;
    BUT I am unable to create variable with boolean data type.
    WARNING. Do not confuse SQL*Plus with PL/SQL.
    There is no variable command in PL/SQL. PL/SQL does support the boolean data type.
    There is a variable command in SQL*Plus. It allows one to define bind variables. It is limited in the data types it supports. It does not support boolean as a bind variable type.
    SQL*Plus is a CLI (Command Line Interface) client tool. It has a very limited vocabularly, allowing you to (primarily):
    a) configure its local environment (e.g. size of the terminal ito number of characters per lines)
    b) configure its bevahiour (e.g. spooling data to a file)
    c) defining substitution and bind variables
    And that's it. It is not PL/SQL. It is not SQL. It takes the PL/SQL and SQL you enter, and submit that to the Oracle server. (it does some basic parsing of the data to substitute variables and bind variables where applicable)
    Do not confuse this CLI client tool with the server side PL/SQL or SQL languages.

  • Using Case and Joins in update statement

    Hi all,
    I need to update one column in my table...but need to use case and joins...I wrote the query and it is not working
    I am getting an error msg saying...the SQL command not ended properly...
    I am not that good at SQL...Please help...
    update t1 a
    set a.name2=
    (case
    when b.msg2 in ('bingo') then '1'
    when b.msg2 in ('andrew') then '2'
    when b.msg2 in ('sam') then '3'
    else '4'
    end )
    from t1 a left outer join t2 b
    on a.name1 = b.msg1 ;
    Waiting for help on this...!
    Thanks in Advance... :)

    Another approach is to update an inline view defining the join:
    update
    ( select a.name2, b.msg2
      from   t1 a
      join   t2 b on b.msg1 = a.name1 ) q
    set q.name2 =
        case
          when q.msg2 = 'bingo' then '1'
          when q.msg2 = 'andrew' then '2'
          when q.msg2 = 'sam' then '3'
          else '4'
        end;which could also be rewritten as
    update
    ( select a.name2
           , case q.msg2
                when 'bingo'  then '1'
                when 'andrew' then '2'
                when 'sam'    then '3'
                else '4'
             end as new_name
      from   t1 a
      join   t2 b on b.msg1 = a.name1 ) q
    set name2 = new_name;The restriction is that the lookup (in this case, t2.msg1) has to be declared unique, via either a primary or unique key or unique index.
    (You don't strictly need to give the view an alias, but I used 'q' in case you tried 'a' or 'b' and wondered why they weren't recognised outside the view.)

Maybe you are looking for

  • Allowing another computer to access my network

    I bought an Airport Extreme Base Station for my roommate and I to share. I set up the network, and I can access the network and get on the internet, but she cannot. She can access the network and gets an excellent signal, but it is just a local conne

  • HT3529 how to do i send a text conversation with all the detail to my email?

    How to do I send a text conversation with all the detail from my phone to my email?

  • Flex Builder installed as Plugin strangeness

    Re: Beta 3 of Flex Builder, i've got the standalone version installed on my laptop and the plugin version on my desk machine. All's fine with the standalone version. I'm working thru the Lessons in the Getting Started Tutorials, and when i change the

  • Tax code in Invoice verification

    Hi I have created a PO where there is no input tax. The GR has been done. When posting the invoive it is asking for the tax code. Why ? I have mantained a tax code V0 for the country . Then I am getting the following message. Tax code V0 country KE d

  • Brother hl2270dw installer program locks up

    whenever i tried to set up my brother hl 2270dw printer to my new wireless network, the brother wireless setup app locks up when it tries to find wifi networks. I never had this issue before, so I assume this is a java related issue since this app is