Comparison of multiple column values with a single column value

I have two separate tables say Tab1 and Tab2
I want to select some datas , which is common to both the tables.
In tab1 , there is a column 'STATE' and it's value is 'A'
In tab2, there are multiple columns for the state, say STATE_A,STATE_B, STATE_C ETC and a row is present with the following details
STATE_A = 1, STATE_B =1 ,STATE_C =0,STATE_D=1
I need to select STATE when STATE_A ='1',
if my STATE='B', this STATE has to be selected since STATE_B =' 1', similraly
if my STATE='D', this STATE has to be selected since STATE_D =' 1',
If my STATE='C', STATE_C should not get selected since it's '0'.
Is it possible to do this in a single SELECT statement, where I have some other checks also or else how can I achieve it?

Maybe this will help
Select * from STATE_MAS ;
STATE
A
B
D
F
H
Select * from STATE_CHILD
  STATE_A   STATE_B   STATE_C   STATE_D   STATE_E   STATE_F   STATE_G   STATE_H   STATE_I   STATE_J
        1         0         0         1         1         0         0         0         0         0
CREATE OR REPLACE FUNCTION GET_STATE (P_VAL VARCHAR) RETURN NUMBER IS
V_SQL VARCHAR2(200);
V_COL VARCHAR2(35);
P_RETURN NUMBER ;
BEGIN
V_COL := 'STATE_'||P_VAL;
V_SQL := 'SELECT 1 FROM STATE_CHILD WHERE '||V_COL||' = 1 ';
EXECUTE IMMEDIATE  V_SQL INTO P_RETURN ;
RETURN P_RETURN ;
END;
SELECT STATE FROM STATE_MAS
WHERE GET_STATE(STATE) = 1 ;
STATE
A
D

Similar Messages

  • Library Filters: Filter for multiple values in a single column and Wildcards

    If you have a multi-value column in a library, can you filter to show only results where two (or more) specific values (terms) are applied? E.g. Year 2014 and Month January? Seems this would be particularly useful for Enterprise Keywords columns.
    Similarly, is there any way to filter on one value OR another value in a single column (e.g. Document Type Memo OR Fax)?
    Any way to use wildcards in searches (would be REALLY useful in the Title and Name columns when naming conventions have been followed).
    I'm guessing the answer is going to be 'move to SharePoint 2013' - if that is the case, please confirm whether all the scenarios mentioned above are catered for.

    Thanks for your replies !
    Is there any other way to achieve this ?
    There is 1 InfoObject which has 2 fields Employee and Department.
    Employee     Department
    001                A
    001                B
    001                C
    In the report there should be 1 row for Employee 001 with all the Departments displayed in the same cell separated by commas.
    Can this be done in the backend through a ABAP code?

  • Multiple vendor payments with a single u201CYOURSELFu201D cheque

    Hi,
    How do we handle multiple vendor payments with a single u201CYOURSELFu201D cheque, drawn in favor of the paying banker? OR NEFT transfers in SAP.
    Thanks,
    M. Senthil

    Hi
    First things first:
    1. You want to create a single payment document for multiple vendors.  In such a case, you will not be able to use F110. You need to use F-53 or F-f8 in such a case. In the all the vendor masters, maintain the alternative payee with Description as "YOURSELF". There after, if you are using F-53, use FBZ5 to print the cheque in the name of alternative payee.
    2. if you are using F110, multiple payment documents will be created for different vendors. In FBZP Config, you can assign the Payment Advise Form in the Payment Method Step in FBZP Config
    Regards
    Sanil

  • How do you combine a stacked column chart with a clustered column chart

    Hello,
    I am trying to combine a stacked column chart with a clustered column chart. I know that in Excel there is a way to trick that described on the next site: http://people.stfx.ca/bliengme/ExcelTips/Columns.htm
    Is that possible with BI Publisher?
    Thank you very much!
    Codruta Crisan

    Finally I get it myself:
    You need to use graph type as BAR_VERT_STACK2Y and the declare the series that you want to see on the first Y vertical bar as assignedToY2="false" and the ones that you wanr to see on the second Y vertical bar as assignedToY2="true".
    In my case I use 4 Series, 2 stack on the first clustured column and 2 stacked on the second (2Y) clustured colum....see below
    graphType="BAR_VERT_STACK2Y">
    <SeriesItems>
    <Series id="0" assignedToY2="false" color="#BBD6E7"/>
    <Series id="1" assignedToY2="false"/>
    <Series id="2" assignedToY2="true" color="#004A96"/>
    <Series id="3" assignedToY2="true"/>
    </SeriesItems>

  • Multiple Display Types in a single column

    I have a situation where I have to display a bunch of attributes for a customer. Each attribute can have a different type, Text, Dropdown, Date etc and that information is stored in a table.
    I was able to use apex_item to display the different display types based on the type of attribute.
    So the layout of the form has 2 columns, column 1 is the name of the attribute and column 2 is the value of the attribute (displayed as the various types of date, text, dropdown etc) However, I am having an issue with the Date popups. When I select a date it always goes into whatever date is listed first. No sorting is going on in the select or the report.
    I'm guessing my issue has to do with displaying different display types in the same column? If that is true, how should I change my approach to this problem? I want all the attributes on a single page, so is my only option to have each attribute in a different region?
    Thanks,
    -- Johnnie

    Denes,
    OK thanks for the heads up, let me try to clarify.
    My problem is that I have multiple date popups on the same form. When I pick a date for any of the date popups, it always updates the first date popup field on the form. I stated there was no sorting at all because this thread indicated that sorting could cause this issue:
    DATE_POPUP
    Another hit for this issue was here:
    Re: HTMLDB_ITME.DATE_POPUP problems
    This suggested that having multiple data types in the same column (which is what I am doing) is not supported, but this is an old thread.
    My form will be a manual tabular form. I need to display a list of attributes, however some are freeform text, some are SQL LOV dropdowns, and some are date popups. Right now they are all displayed in the same column. Could this be causing my date popup issue? If so what alternatives do I have?
    Screenshot of my form here: http://johnniebillings.googlepages.com/outlook.jpg
    Hope that clears up the issue I am having.
    -- Johnnie

  • Newbie questions: 'extracting' values from a single column. Is it possible?

    Hello everybody,
    I'm a pretty newbie user of BI 11. I would like to know if it's possibile to aggregate values by filtering different values in a same column. As my English is quite bad, let me summarize my problem with an example:
    Column A - Number of Recevived Calls -- Column B Caller's Satisfaction Rating
    A: 12 - B: Good
    A: 25 - B: Average
    A: 100 - B: Perfect
    A: 35 - B: Not good enough
    I would like to be able to do some math with single scores as, for instance, to group together good, average and perfect scores and remove the not good enough scores, or, another example, I'd like to calculate the percentage of GOOD ratings on the total number of calls.
    Anyone can help me? I'm a simple user of the BI frontend, so I don't have access to the underlying database structure.
    Sorry for any mistake I made in my English writing and Thanks a lot in advance.

    I assume Column A is a measure. In the edit formula for this column, highlight the column and filter it based on column B. For example you might to filter all the calls for 'Good' then you may divide it by total no of calls or something similar. It might look something like this -- Filter(table.column A USING (table.Column B = 'Good'))/Sum(table.columA)
    you might want to use a combination of case statements as well depending on what you want to achieve.
    for example -- case when table.column B='GOOD' then sum(table.column A) else (sum(table.column A)/(case when table.column B='BAD' then sum(table.column A) end))end
    Give it a try, hope this helps.

  • Using sql load insert multiple fields data into a single column in database

    Hi ,
    I have my log file in sun OS box something like this
    =======
    (07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
    (07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
    (07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
    =============
    I am trying to insert the data into oracle data base as follows.
    =============================
    column1 : (07/29/2009 00:02:24.467)
    column2 : 367518
    column3 : (07/29/2009 00:02:26.214)
    column4 : 949384011
    ===========================
    Can anyone help me with the control file format?
    someone suggested me the code below.
    ==========
    LOAD DATA
    INFILE 'D:\work\load.txt'
    INTO TABLE sample
    (col1 POSITION(02:24) char,
    col2 POSITION(27:32) INTEGER EXTERNAL,
    col3 POSITION(35:57) CHAR,
    col4 POSITION(60:68) INTEGER EXTERNAL
    ===========
    but this works only for the fixed length data? Please help

    user11744904 wrote:
    Hi ,
    I have my log file in sun OS box something like this
    =======
    (07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
    (07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
    (07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
    =============
    I am trying to insert the data into oracle data base as follows.
    =============================
    column1 : (07/29/2009 00:02:24.467)
    column2 : 367518
    column3 : (07/29/2009 00:02:26.214)
    column4 : 949384011
    ===========================
    Can anyone help me with the control file format?
    someone suggested me the code below.
    ==========
    LOAD DATA
    INFILE 'D:\work\load.txt'
    INTO TABLE sample
    (col1 POSITION(02:24) char,
    col2 POSITION(27:32) INTEGER EXTERNAL,
    col3 POSITION(35:57) CHAR,
    col4 POSITION(60:68) INTEGER EXTERNAL
    ===========
    but this works only for the fixed length data? Please helpIs the requirement to load all data in a single column or multiple columns? The thread subject and body are conflicting.

  • Multiple iTunes accounts with a single ipod?

    I just bought my daughter a new ipod Touch.  Will she be able to download music into the ipod from both my itunes account and from her mom's seperate itunes account, or will her ipod only be able to be associated with a single itunes account?  Thanks.

    You can use multiple iTunes accounts on one iPod.  Just note that you can only sync with one iTunes library/computer.  However, yu can manage music among different computers. See:
    Using iPhone, iPad, or iPod with multiple computers

  • Replace multiple space characters with a single space

    Hi,
    Oracle 11g R2.
    Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
    select replace(column1, chr(32)||chr(32), chr(32)) from tablea

    Hi,
    If you had to do this without regular expressions, you could use:
    SELECT  REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
                     , ' ~'
              , '~ '
              )     AS new_str
    FROM    table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
    However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler.

  • Is it possible to maintain multiple payment formats with a single Program

    Hi,
    Is it possible to maintain multiple payment formats with in a single program.
    For example let us assume that we have created 2 payments formats as 'XX-PAY1' & 'XX-PAY2'.
    When i select the parameter as '1' then 'XX-PAY1' has to run else 'XX-PAY2'.
    if its possible could you please tel us where to define the parameters in Setups.
    Many thanks,
    Zaheer S

    nazzu wrote:
    Hi,
    Is it possible to maintain multiple payment formats with in a single program.
    For example let us assume that we have created 2 payments formats as 'XX-PAY1' & 'XX-PAY2'.
    When i select the parameter as '1' then 'XX-PAY1' has to run else 'XX-PAY2'.
    if its possible could you please tel us where to define the parameters in Setups.
    Many thanks,
    Zaheer SSounds like an Apps question. Start here: https://forums.oracle.com/forums/category.jspa?categoryID=3

  • Multiple Form Regions with a single Save button

    Hello,
    Is it possible to have multiple form regions on a single page, with a single Save button that commits changes in all form regions? If so, would the forms have to be manual forms?
    If that is not possible, or a bad way to go with APEX, what are my alternatives?
    I am trying to avoid the user having to click through many screens to input the data. Logically each section should be in a different table, but I would like to group some of the sections together to reduce the number of pages the users need to navigate to.
    Thanks in advance for your help,
    Johnnie
    Edited by: johnniebillings on Jun 1, 2009 9:33 PM

    Hi Johnnie,
    I assume that the tables are related somehow?
    If so, you can create a SQL View on the joined tables (making sure that you have a unique ID for each record in the view that can act as the Primary Key), base the form on that view and then use an INSTEAD OF trigger on the view to populate the individual tables.
    Andy

  • Popup List with multiple columns but returning a single column (key value)

    Hi,
    1. Is it not possible to show a POPup (returning a key value) or Select list with more than 1 column? If so how?
    2. I have an item in a page which should be hidden if 1 particular button was pressed. This is is to use the same page but have some behavioural change based on which button (option) was selected. How can I get the name of the BUTTON PRESSED TO INVOKE THIS PAGE.
    thanks
    SebJos

    Hi,
    In that case, you should make the page item conditional. There are many techniques to do this but it would depend on what the button is for.
    As a simple example...
    1 - Create a hidden item on your page called, say, Pn_SHOW (replace n with your page number - eg, P1_SHOW). Set the default value of this item to either 0 (zero) or 1 - 0 will hide the item and 1 will display it, so in your example, set it to 0
    2 - On the page item you want to show/hide - on its definition, you have a Conditions section. Set the following:
    Condition Type: Value of Item in Expression 1 = Expression 2
    Expression 1: P1_SHOW
    Expression 2: 1
    When the page is loaded, because the value of P1_SHOW is 0, and due to the conditions we have just set (where P1_SHOW must be 1 for the item to be shown), the item will not appear on the page.
    When you created your button, a new page branch should have been created. On this branch, you have two settings - "Set these items" and "With these values". Set the following:
    Set these items: P1_SHOW
    With these values: 0
    You should also have at least one other branch on your page - one of these will need to set the value of P1_SHOW to 1 to get the item to display.
    Andy

  • Finding the minimum value across multiple rows (not in a single column)

    Hello,
    I am running some ad-hoc SQL to test a website implementation of a spec. The ad-hoc sql gives me a set of date values for a specific widget (called a Task). I need to find the Minimum of either (Task.EndDate + 1 year) or the MAX date from the list
    of other dates. I can easily get all of these dates, and compare them visually, but I'm not sure how to make SQL give me just the single value that I want. In the image below, you can see the results. The blue cell is the value I should get if I were to retrieve
    a single value. 
    select 
    [EndDate+12Mo] = DATEADD(year,1,t.EndDate)
    , [TaskEdit] =  t.EditTS
    , [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
    , [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
    , [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
    , [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
    , [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
    , [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
    , [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner join ContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
    from task t
    where 
    t.tasknumber = 
    '2123.001'
    Thanks!
    Jennifer

    Sounds like this to me
    select CASE WHEN [EndDate+12Mo] < MAX(dt) THEN [EndDate+12Mo] ELSE MAX(dt) END AS YourDateValue
    from
    SELECT [EndDate+12Mo],dt
    from
    select
    [EndDate+12Mo] = DATEADD(year,1,t.EndDate)
    , [TaskEdit] = t.EditTS
    , [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
    , [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
    , [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
    , [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
    , [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
    , [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
    , [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner JOINContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
    from task t
    where
    t.tasknumber =
    '2123.001'
    )t1
    UNPIVOT(dt FOR cat IN ([TaskEdit]
    , [ResearchEdit]
    , [DeliverableEdit]
    , [RTPEdit]
    , [RelatedTaskEdit]
    , [CrosscutEdit]
    , [TaskFundingEdit]
    , [ContractFundingEdit]))u
    )r
    GROUP BY [EndDate+12Mo]
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • SQL Query constructing  for searching values in Tables single Column

    I have Table USER_SERVICES with 2 Columns USER_NAME, Services. Please find below sample data on USER_SERVICES Table.
    A user can be assigned with multiple services(service1, service2 etc.,). So we store data as below :
    USER_NAME Services
    user1 service1
    user1 service2
    user1 service3
    user2 service1
    user2 service2
    user3 service3
    user4 service4
    I need to frame a SQL Query to 'select users assigned with Service A and Service B and Service n'.
    Note: 'And' condition is used when Searching for multiple services.
    Example: The SQL Query has to dynamically handle condition if i give Single Service, multiple Services(service1 and service2 e.t.c,)
    If i say select users assigned with service1 and service2, from the above Table, result should be user1 and user2
    If i say select users assigned with service1 and service2 and service3, from the above Table, result should be user1
    If i say select users assigned with service4 from the above table, result should be user4
    If i say select users assigned with service1 from the above table, result should be user2,user1
    If i say select users assigned with service1 and service2 from the above table, result should be user2,user1
    How do i construct the SQL Query. Any help will be appreciated.
    Thanks,
    Sathish
    Alternate email: [email protected]

    How it will be stored? In a string or a table or a collection type?
    If you have it in a table you can do like this.
    with t
    as
    select 'user1' user_name, 'service1' services from dual union all
    select 'user1', 'service2' from dual union all
    select 'user1', 'service3' from dual union all
    select 'user2', 'service1' from dual union all
    select 'user2', 'service2' from dual union all
    select 'user3', 'service3' from dual union all
    select 'user4', 'service4' from dual
    t1 as
    select 'service1' services from dual union all
    select 'service2' from dual
    select distinct user_name
      from (
    select t.user_name, t.services, t1.services, count(t1.services) over(partition by t.user_name) cnt, t1.cnt cnt_1
      from t
      left join (select t1.*, count(*) over() cnt from t1) t1 on t1.services = t.services
    where cnt = cnt_1

  • Inserting value in the single column table where the only column is a identity column

    Hi,
    Following is my table definition:
    create table test1 (col1 int primary key identity(1,1))
    Now here, the only column col1 in the table is an identity column. Now I want to add explicit values to this column
    without SET Identity_Insert test1 On.
    How?

    You have a fundamental misconception. IDENTITY is not a column; it is a table property and it is totally non-relational. This is a left-over from UNIX file systems, which were built on magnetic tape files. It is a sequential data
    model which counts the insertion attempts to get a physical record number. By definition IDENTITY cannot be a valid key; it is not a valid data type (all data types in SQL are NULL-able); keys are a subset of columns in a table. 
    Have you ever read a single book on RDBMS? You can start with MANGA GUIDE TO DATABASE, it is the clearest intro book I know. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • How do I create a connection string to sql server?

    Hi All,    I am currently connecting to a SQL Server via ODBC DSN connection. I am wondering how do I create a connection string directly to a sql server without a DSN connection? Thank you in advance.

  • Web Service WSDL File Generation

    hello everybody, I have an outbound interface with sender soap adapter to work as a web service, I tested it by generating the wsdl file in the integration directory, and I tested it with altova xmlspy and it works really fine, but now I have a probl

  • I cant print i get the printer spool service message

    i have pavallion a1737c and i cant print!!! i get the printing spool service is not running,  i have tried to turn on the spooler in the services area but no luck,  can someone please help

  • TFT screen blinks strange at wake up

    Hi folks, since a few weeks I got strange problem with my TFT screen. My mini is setup to put the monitor to sleep after 20 minutes inactivity. This works flawless. However, every time the screen wakes up it starts with about one minute blinking of '

  • Crosstab Aging report

    <p>This is prabably a really simple problem, but I can't figure out how to do it.</p><p> I want to create a crosstab report that has some categories as the rows and aging ranges (<30 days, 31-60, 61-90, 91-180, 180) as the columns, with a count of ho