SQL Join with results in one line with multiple conditions

First post, new to the forum!
I have two tables which I am querying from, as an example
select a.f_name || a.l_name, case when b.bodypart='Arm' then ='Arm' end, case when b.bodypart='Leg' then 'Leg' end
from person a
join bodyparts b on b.person_id=a.person_id
where b.bodypart in ('Arm','Leg')
What this gives is something like:
BobNewhart Arm (null)
BobNewhart (null) Leg
I am trying to get the following results:
BobNewhard Arm Leg
This is just an example, but this should give a valid picture of the issue which i am having.
Thank you for any help!
Richie

Hi,
Like Whitehat said, use GROUP BY. You don't need a sub-query; just GROUP BY the name, and use MIN or MAX around the CASE expressions:
SELECT        a.f_name || a.l_name
,        MAX ( CASE
             WHEN b.bodypart='Arm'
             THEN ='Arm'
             END
           )          AS arm
,        MAX ( CASE
             WHEN b.bodypart='Leg'
             THEN ='Leg'
             END
           )          AS leg
FROM       person           a
JOIN       bodyparts      b  ON      b.person_id     = a.person_id
WHERE       b.bodypart      IN ('Arm','Leg')
GROUP BY  a.f_name || a.l_name
;Since there will only be one value (at most) in the arm and leg columns, it doesn't matter if you use MIN or MAX.

Similar Messages

  • Outer Joins with multiple conditions - alternatives to UNION?

    It is my understanding that Oracle 8i does not directly support mutiple conditions for outer joins. For instance, I'm looking for PEOPLE who may, or may not, be on MEDICATIONS.
    All MEDICATIONS are listed with DRUGNAME and DRUGID. There thousand of different drugs. I'm only looking for PEOPLE on either one or two of them (to make it simple) or no drug at all (ignoring all other DRUGS they're on..) IF they are on the DRUG, it's gerts printed.
    I'd ideally do a LEFT OUTER JOIN to do this with multiple conditions:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    (MEDICATION.DRUGID (+) = 632 OR
    MEDICATION.DRUGID (+) = 956)
    This, of course, is not valid, at least in 8i...
    So I've taken the UNION approach:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 632
    UNION
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 956
    This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
    In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
    -- Any suggestions for alternative syntax ???
    -- Has this been addressed in 9i ???
    Thanks,
    Will

    You could try
    select Distinct Person.Name, Med.DrugName, Med.DrugId
    from Person,
    (select ID, DrugName, DrugId from Medication
    where DrugId in (632, 956) ) Med
    where Person.ID = Med.ID(+)
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    (MEDICATION.DRUGID (+) = 632 OR
    MEDICATION.DRUGID (+) = 956)
    This, of course, is not valid, at least in 8i...
    So I've taken the UNION approach:
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 632
    UNION
    SELECT DISTINCT
    PERSON.NAME,
    MEDICATION.DRUGNAME,
    MEDICATION.DRUGID
    FROM
    PERSON,
    MEDICATION
    WHERE
    PERSON.ID = MEDICATION.ID (+) AND
    MEDICATION.DRUGID (+) = 956
    This of course, does work, but as I've added more drugs this becomes quite unwieldly and not really sure what this does to performance. (There are also several more joins to other tables, not relevent here.)
    In addition, if I import this into Crystal Reports 8.5 (as opposed to the Crystal Query Designer), it refuses to recognize the UNION.
    -- Any suggestions for alternative syntax ???
    -- Has this been addressed in 9i ???
    Thanks,
    Will

  • Left outer join with multiple conditions

    Is it possible to add to a left outer join (= anyOfAllowingNone) more than the primary condition (in SQL this would be added per "and").
    Background: The execution plan of the produced SQL shows large results on which the final filter is applied although I have conditions that would decrease this last result set much earlier...

    There is no easy way to do this in TopLink expressions, other than including the join in the regular where clause as you have done. Does it make a big impact in the performance of your query?
    <p>
    You could use custom SQL for the query.
    <p>
    Or you could potentially define a OneToOneQueryKey in your TopLink descriptor that includes the additional join criteria and call anyOfAllowingNone using this query key.
    <p>
    <p>---
    <p>James Sutherland

  • SQL query with multiple condition

    Below is the sample table
    ID     RATE     DATE     ORGAMNT     PAYAMOUNT
    1     3.45     12/23/2012     23000.45     19060.23
    2.    5.50     04/12/2013     45000.00     36000.54
    3.     6.44    04/16/200     60000.00     20000.00
    Select a table with highest rate, Orgamnt with Date closer to current date.

    with
    data_table as
    (select 11186 hnum,11607400 oma,to_date('2/1/2006','mm/dd/yyyy') fpay,5.51 irate,10580934.67 apb,'WELLS FARGO BANK NA' hname from dual union all
    select 11188,4801800,to_date('9/1/2006','mm/dd/yyyy'),6.3,4326951.51,'PNC BANK, NATIONAL ASSOCIATION' hname from dual union all
    select 11189,1236100,to_date('8/1/2006','mm/dd/yyyy'),6.15,1147108.9,'HEARTLAND BANK' hname from dual union all
    select 11192,1578400,to_date('4/1/2007','mm/dd/yyyy'),5.82,1470926.86,'WELLS FARGO BANK NA' hname from dual union all
    select 11193,8150400,to_date('12/1/2008','mm/dd/yyyy'),6.75,7828776.28,'OPPENHEIMER MULTIFAMILY HSG' hname from dual union all
    select 11195,3898000,to_date('5/1/2009','mm/dd/yyyy'),6.5,3752154.96,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11196,8040000,to_date('6/1/2009','mm/dd/yyyy'),7,7775734.57,'OPPENHEIMER MULTIFAMILY HSG' hname from dual union all
    select 11197,37315000,to_date('12/1/2009','mm/dd/yyyy'),5.5,35851362.87,'RED MORTGAGE CAPITAL LLC' hname from dual union all
    select 11199,3824000,to_date('2/1/2010','mm/dd/yyyy'),5.25,3673760.35,'WALKER AND DUNLOP LLC' hname from dual union all
    select 11200,26927000,to_date('7/1/2010','mm/dd/yyyy'),4.7,25186682.65,'OAK GROVE COMMERCIAL MORTGAGE' hname from dual union all
    select 11201,7208600,to_date('10/1/2010','mm/dd/yyyy'),4.59,6949026.64,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11204,9300000,to_date('2/1/2011','mm/dd/yyyy'),3.41,8927064.51,'PNC BANK, NATIONAL ASSOCIATION' hname from dual union all
    select 11205,5200000,to_date('2/1/2011','mm/dd/yyyy'),3.56,4997518.18,'LOVE FUNDING CORPORATION' hname from dual union all
    select 11206,6800000,to_date('5/1/2011','mm/dd/yyyy'),3.88,6576635.57,'WELLS FARGO BANK NA' hname from dual union all
    select 11208,12240000,to_date('8/1/2011','mm/dd/yyyy'),3.84,11879882.17,'WELLS FARGO BANK NA' hname from dual union all
    select 11209,12911500,to_date('10/1/2011','mm/dd/yyyy'),3.55,12542199.51,'M AND T REALTY CAPITAL CORP' hname from dual union all
    select 11210,9596900,to_date('7/1/2011','mm/dd/yyyy'),5.38,9323421.23,'LANCASTER POLLARD MORTGAGE' hname from dual union all
    select 11211,19951600,to_date('9/1/2011','mm/dd/yyyy'),3.88,19393524.45,'DEUTSCHE BANK BERKSHIRE MORTGAGE' hname from dual union all
    select 11183,4230000,to_date('4/1/2009','mm/dd/yyyy'),6.55,4069938.75,'BERKADIA COMMERCIAL MORTGAGE' hname from dual union all
    select 11212,50475000,to_date('1/1/2013','mm/dd/yyyy'),2.37,49852632.51,'LOVE FUNDING CORPORATION' hname from dual union all
    select 11213,5496000,to_date('5/1/2012','mm/dd/yyyy'),3.1,5377541.15,'WELLS FARGO BANK NA' hname from dual
    select hnum,oma,fpay,irate,apb,hname,r_oma,r_irate,r_fpay,0.5 * r_oma + 0.3 * r_irate + 0.2 * r_fpay r
      from (select hnum,oma,fpay,irate,apb,hname,
                   dense_rank() over (order by oma desc) r_oma,
                   dense_rank() over (order by irate desc) r_irate,
                   dense_rank() over (order by (sysdate - fpay)) r_fpay
              from data_table
    order by r
    HNUM
    OMA
    FPAY
    IRATE
    APB
    HNAME
    R_OMA
    R_IRATE
    R_FPAY
    R
    11197
    37315000
    12/01/2009
    5.5
    35851362.87
    RED MORTGAGE CAPITAL LLC
    2
    9
    12
    6.1
    11212
    50475000
    01/01/2013
    2.37
    49852632.51
    LOVE FUNDING CORPORATION
    1
    20
    1
    6.7
    11211
    19951600
    09/01/2011
    3.88
    19393524.45
    DEUTSCHE BANK BERKSHIRE MORTGAGE
    4
    14
    4
    7
    11200
    26927000
    07/01/2010
    4.7
    25186682.65
    OAK GROVE COMMERCIAL MORTGAGE
    3
    12
    10
    7.1
    11209
    12911500
    10/01/2011
    3.55
    12542199.51
    M AND T REALTY CAPITAL CORP
    5
    17
    3
    8.2
    11210
    9596900
    07/01/2011
    5.38
    9323421.23
    LANCASTER POLLARD MORTGAGE
    8
    10
    6
    8.2
    11196
    8040000
    06/01/2009
    7
    7775734.57
    OPPENHEIMER MULTIFAMILY HSG
    11
    1
    13
    8.4
    11208
    12240000
    08/01/2011
    3.84
    11879882.17
    WELLS FARGO BANK NA
    6
    15
    5
    8.5
    11193
    8150400
    12/01/2008
    6.75
    7828776.28
    OPPENHEIMER MULTIFAMILY HSG
    10
    2
    16
    8.8
    11186
    11607400
    02/01/2006
    5.51
    10580934.67
    WELLS FARGO BANK NA
    7
    8
    20
    9.9
    11204
    9300000
    02/01/2011
    3.41
    8927064.51
    PNC BANK, NATIONAL ASSOCIATION
    9
    18
    8
    11.5
    11201
    7208600
    10/01/2010
    4.59
    6949026.64
    BERKADIA COMMERCIAL MORTGAGE
    12
    13
    9
    11.7
    11206
    6800000
    05/01/2011
    3.88
    6576635.57
    WELLS FARGO BANK NA
    13
    14
    7
    12.1
    11183
    4230000
    04/01/2009
    6.55
    4069938.75
    BERKADIA COMMERCIAL MORTGAGE
    17
    3
    15
    12.4
    11195
    3898000
    05/01/2009
    6.5
    3752154.96
    BERKADIA COMMERCIAL MORTGAGE
    18
    4
    14
    13
    11188
    4801800
    09/01/2006
    6.3
    4326951.51
    PNC BANK, NATIONAL ASSOCIATION
    16
    5
    18
    13.1
    11213
    5496000
    05/01/2012
    3.1
    5377541.15
    WELLS FARGO BANK NA
    14
    19
    2
    13.1
    11205
    5200000
    02/01/2011
    3.56
    4997518.18
    LOVE FUNDING CORPORATION
    15
    16
    8
    13.9
    11199
    3824000
    02/01/2010
    5.25
    3673760.35
    WALKER AND DUNLOP LLC

  • SQL JOIN with BPM sql component

    Hello friends.
    How to use SQL JOIN with BPM sql component?
    The tables objects are created but the joined tables belong to different sql components .
    I tried something like that, but a error "table doesn't exist" occours.
    Ex:
    for each element in
    SELECT imuImovelCd
    FROM IMOVEIS_URBANOS,
    Integracao.FGLP.IMOVEIS_PRE_EDITAIS
    WHERE IMOVEIS_URBANOS.imuImovelCd = Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipeImuCd
    AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
    AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
    do
    extend this.imoveis using cdImovel = element.imuimovelcd,
                                  nrImovel = call(DEC_ENDERECO, codimovel : element.imuimovelcd, tipoimovel : 1)
    end
    Edited by: user9008295 on 26/01/2010 05:19

    ok, ok you are right.
    When I try use SQL Statement to make a JOIN with 2 tables on different sql objects, BPM returns "table dosn't exists".
    So.... I change my code. I dont know if this is the best way to do, but... i hope u, or everyone, can help me to do a best work.
    This code works fine.
    for each element in
    SELECT ipeImuCd
         FROM Integracao.FGLP.IMOVEIS_PRE_EDITAIS
         WHERE Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
         AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
    do
         for each element2 in
              SELECT imuImovelDv
              FROM IMOVEIS_URBANOS
              WHERE imuImovelCd = element.ipeImuCd
         do
              extend this.imoveis using cdDvImovel = String(element2.imuImovelDv),
                                            cdImovel = Decimal(element.ipeImuCd),
                                            endereco = call(DEC_ENDERECO, codimovel : element.ipeImuCd, tipoimovel : 1)
         end
    end
    Thx a lot!!!

  • Sql server with multiple instance

    hi  All,
    i want  to  install sql server with two instance   and i want  to assign two  separate is  ips   for  both   default instance  and named  instance   and  both   should  work like
    two different server
    note:  If i  logged  with  one  ip(default instance)   it should  show  its  own  databases  not both or  named   instance  databases
    thanks 
     chintala

    Hi chintala,
    According to your description, if you want to assign the two different IP to stand for default instance 
    and named  instance, I recommend you set up aliases on a SQL Server with multiple instances. For example, a physical server is named WinServer and 2 instances of SQL Server named WinServer and WinServer\instance1.
    We need to add 1 IP addresse to the WinServer, there is one IP address already assigned to WinServer, 192.168.1.1, by adding one new IP's, 192.168.1.2 .
    We need to move into DNS to configure our host names and aliases.  The physical machine must be steup as a static IP in DNS. SQLAlias1, which point to the default instance on WinServer, will be setup as a DNS with an address of 192.168.1.1.
    SQLAlias2, which will point to WinServer\Instance1, will be setup as a new Host (A) record in DNS with an address of 192.168.1.2.
    When everything has been completed on the DNS side, you need to open up SQL Server Configuration Manager on WinServer and configure the protocols for each instance one at a time, restart the 3 SQL services.
    For more information about how to set up aliases on a SQL Server with multiple instances, you can review the similar article.
    http://kevine323.blogspot.com/2013/08/setting-up-aliases-on-sql-server-with.html
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • I need your expert opinion on how to create a map with multiple conditions.

    Hello.
    I need your expert opinion on how to create a map with multiple conditions.
    I have a procedure (which i cannot import or re-create in OWB due to the bug), so i am trying to create a map instead :-(
    How can i create a cursors within the map?
    My function creates table and cursor.
    Then it will have to check for duplicates in the tables (the one created and another table) - the criteria for finding duplicates is a number of fields.I then need to place few different conditions (if some attributes are not available) and it has to load cursor based on this conditions. The next step is to fetch the data into the cursor based on what attributes are missing.
    The next thing it will do is insert the data into table (if record doesn't exist), output the error in separate table is record is corrupted, or update the record with changed information.
    In short i need to re-create match / merge but with conditions, iterations etc 'built into' it.
    I can read up on available functions - it's just what would be the best options? and what would be the best approach to do so?
    In my function i use %rowtype - but cannot use it in owb - so what would be the alternative? i don't really want to create a lot of variables and then have a nightmare of maintaing it. are there any tips regarding this?
    having looked through Oracle dedupe - it's not really what i need because it is just DISTINCT.
    I would appreciate any help / advise on this.
    Thank you very much

    thanks a lot for your reply - i will look into this option :-)
    it is a bit more complicated now as i have to re-create the match / merge and then somehow 'tweak' it to achieve the result i need.
    At the moment i am looking to breakdown the package into smaller chunks 'functions' and try creating the map that way.
    Anyway, thank you very much for your suggestion.

  • Copy the inspection  result  from one lot to multiples lots!!

    Hi SAP expert,
    I want to copy the inspection  result  from one lot to multiples lots, currently i know how to setup  the copy to another lot(SAML Response from SAP ID Service ) , but  i dont know to do to multiples lot.
    ¿Someone can help me?
    Thank you

    First you have to customizing the functionality of Copy of Inspection Results using the following path, where you have to entry the inspection types, plant .etc., where you want to have the functionality.
    SPRO -> Quality Management -> Quality Inspection -> Make Settings for Copy of Inspection Results
    Then when you are in Record Result screen you select Menu -> Edit -> Copy Inspection Results ,
    then a pop-up window is displayed and you filled in with the inspection lot which has the results and then another pop-up window is displayed to select the characteristics that you want to copy.
    A.P.

  • MDX Calculated Member With Multiple Conditions

    I need to create a calculated member in my cube that spans multiple dimensions. A current calculated member looks like this:
    [Employee Hours Category].[Utilization Category].[NON-PTO], [Measures].[Employee Hours]
    This calculated member returns all the hours an employee worked that are not PTO.
    I need to select employee hours but with multiple conditions:
    - [DIM BILL STATUS][Bill Status] equals 0
    - [Employee Hours Time Category].[Time Category] equals "Client Facing"
    - [DIM PROJECT].[Client] isn't like "Olson"
    I know this is probably pretty easy, but I'm horrible with MDX!
    Thank you!!
    A. M. Robinson

    Thank you...
    Your answer looks good but I was actually able to figure out most of it, but still looking how to incorporate a FILTER into the MDX. I would like to FILTER like this:
     FILTER ([DIM Project].[Client].[Client].Members , 
                 NOT InStr([DIM Project].[Client].CurrentMember.MEMBER_NAME, "Olson")
    Heres the MDX I have so far that is working fine:
    ([Employee Hours Time Category].[Time Category].&[Client Facing],
       [DIM BILL STATUS].[Bill Status ID].&[1], [Measures].[Employee Hours])
    Do you just wrap the whole MDX in the filter, and if so, how would that be formatted?
    A. M. Robinson

  • Performance tuning of sql query with multiple joins

    My query takes at least half an hour to execute and the number of records returned are approx 1 lakh records.
    Structure of tables are:
    tblSession : ID,option1,option2,option3,option4,option5,option6,option7,option8,option9.
    tblOption : ID, labelID
    tblLabelDetail  : ID, LABELID, text
    optionID 1 to optionID9 are Foreign keys to table tblOption.ID
    My query is as below : 
    select 
    session.ID 
    ,session.tstamp
    ,session.score
    ,session.hid1
    ,session.hID2
    ,session.hID3
    ,session.collectionID
    ,session.consumerID
    ,session.langID
    ,cons_cust.text1 as    customCons_text1, 
    cons_cust.text2 as customCons_text2, 
    cons_cust.text3 as customCons_text3,
    cons_cust.text4 as customCons_text4,
    cons_cust.text5 as customCons_text5,
    cons_cust.text6 as customCons_text6,
    cons_cust.text7 as customCons_text7,
    cons_cust.text8 as customCons_text8,
    cons_cust.text9 as customCons_text9,
    ld_cons1.text as customCons_option1GUID, 
    ld_cons2.text as customCons_option2GUID, 
    ld_cons3.text as customCons_option3GUID, 
    ld_cons4.text as customCons_option4GUID ,
    ld_cons5.text as customCons_option5GUID, 
    ld_cons6.text as customCons_option6GUID, 
    ld_cons7.text as customCons_option7GUID, 
    ld_cons8.text as customCons_option8GUID, 
    ld_cons9.text as customCons_option9GUID,
    --session
    session_cust.text1 as  session_cust_text1, 
    session_cust.text2 as session_cust_text2, 
    session_cust.text3 as session_cust_text3,
    session_cust.text4 as session_cust_text4,
    session_cust.text5 as session_cust_text5,
    session_cust.text6 as session_cust_text6,
    session_cust.text7 as session_cust_text7,
    session_cust.text8 as session_cust_text8,
    session_cust.text9 as session_cust_text9,
    ld_sess1.text as session_cust_option1GUID, 
    ld_sess2.text as session_cust_option2GUID, 
    ld_sess3.text as session_cust_option3GUID, 
    ld_sess4.text as session_cust_option4GUID, 
    ld_sess5.text as session_cust_option5GUID, 
    ld_sess6.text as session_cust_option6GUID, 
    ld_sess7.text as session_cust_option7GUID, 
    ld_sess8.text as session_cust_option8GUID, 
    ld_sess9.text as session_cust_option9GUID, 
    session_cust.tStamp1,
    session_cust.tStamp2
    from mvSession session with (noexpand)
    inner join tblCollection c on c.ID=session.collectionID AND c.templateID = 405
    left join tblConsumer cons on cons.ID=session.consumerID and cons.sessionYM between 601 and 1412 and cons.sID=105
    left join vCustomConsumer cons_cust on cons_cust.sessionYM between 601 and 1412 and cons_cust.sID=105 and cons_cust.ID=cons.ID
    left join tbloption o_cons1 on o_cons1.id = cons_cust.option1 and  o_cons1.sid = 105
    left join tblLabelDetail ld_cons1 on ld_cons1.labelID = o_cons1.labelID and ld_cons1.langId = 1 and ld_cons1.eid = 107 
    left join tbloption o_cons2 on o_cons2.id = cons_cust.option2 and  o_cons2.sid = 105
    left join tblLabelDetail ld_cons2 on ld_cons2.labelID = o_cons2.labelID and ld_cons2.langId = 1 and ld_cons2.eid = 107 
    left join tbloption o_cons3 on o_cons3.id = cons_cust.option3 and  o_cons3.sid = 105
    left join tblLabelDetail ld_cons3 on ld_cons3.labelID = o_cons1.labelID and ld_cons3.langId = 1 and ld_cons3.eid = 107 
    left join tbloption o_cons4 on o_cons4.id = cons_cust.option4 and  o_cons4.sid = 105
    left join tblLabelDetail ld_cons4 on ld_cons4.labelID = o_cons4.labelID and ld_cons4.langId = 1 and ld_cons4.eid = 107 
    left join tbloption o_cons5 on o_cons5.id = cons_cust.option5 and  o_cons5.sid = 105
    left join tblLabelDetail ld_cons5 on ld_cons5.labelID = o_cons5.labelID and ld_cons5.langId = 1 and ld_cons5.eid = 107 
    left join tbloption o_cons6 on o_cons6.id = cons_cust.option6 and  o_cons6.sid = 105
    left join tblLabelDetail ld_cons6 on ld_cons6.labelID = o_cons6.labelID and ld_cons6.langId = 1 and ld_cons6.eid = 107 
    left join tbloption o_cons7 on o_cons7.id = cons_cust.option7 and  o_cons7.sid = 105
    left join tblLabelDetail ld_cons7 on ld_cons7.labelID = o_cons7.labelID and ld_cons7.langId = 1 and ld_cons7.eid = 107 
    left join tbloption o_cons8 on o_cons8.id = cons_cust.option8 and  o_cons8.sid = 105
    left join tblLabelDetail ld_cons8 on ld_cons8.labelID = o_cons8.labelID and ld_cons8.langId = 1 and ld_cons8.eid = 107 
    left join tbloption o_cons9 on o_cons9.id = cons_cust.option9 and  o_cons9.sid = 105
    left join tblLabelDetail ld_cons9 on ld_cons9.labelID = o_cons9.labelID and ld_cons9.langId = 1 and ld_cons9.eid = 107 
    left join vCustomSession session_cust on session_cust.sessionYM between 601 and 1412 and session_cust.sID=105 and session_cust.ID=session.ID
    left join tbloption o_sess1 on o_sess1.id = session_cust.option1 and  o_sess1.sid = 105
    left join tblLabelDetail ld_sess1 on ld_sess1.labelID = o_sess1.labelID and ld_sess1.langId = 1 and ld_sess1.eid = 107 
    left join tbloption o_sess2 on o_sess2.id = session_cust.option2 and  o_sess2.sid = 105
    left join tblLabelDetail ld_sess2 on ld_sess2.labelID = o_sess2.labelID and ld_sess2.langId = 1 and ld_sess2.eid = 107 
    left join tbloption o_sess3 on o_sess2.id = session_cust.option3 and  o_sess3.sid = 105
    left join tblLabelDetail ld_sess3 on ld_sess3.labelID = o_sess2.labelID and ld_sess3.langId = 1 and ld_sess3.eid = 107 
    left join tbloption o_sess4 on o_sess4.id = session_cust.option4 and  o_sess4.sid = 105
    left join tblLabelDetail ld_sess4 on ld_sess4.labelID = o_sess4.labelID and ld_sess4.langId = 1 and ld_sess4.eid = 107 
    left join tbloption o_sess5 on o_sess5.id = session_cust.option5 and  o_sess5.sid = 105
    left join tblLabelDetail ld_sess5 on ld_sess5.labelID = o_sess5.labelID and ld_sess5.langId = 1 and ld_sess5.eid = 107 
    left join tbloption o_sess6 on o_sess6.id = session_cust.option6 and  o_sess6.sid = 105
    left join tblLabelDetail ld_sess6 on ld_sess6.labelID = o_sess6.labelID and ld_sess6.langId = 1 and ld_sess6.eid = 107 
    left join tbloption o_sess7 on o_sess7.id = session_cust.option7 and  o_sess7.sid = 105
    left join tblLabelDetail ld_sess7 on ld_sess7.labelID = o_sess7.labelID and ld_sess7.langId = 1 and ld_sess7.eid = 107 
    left join tbloption o_sess8 on o_sess8.id = session_cust.option8 and  o_sess8.sid = 105
    left join tblLabelDetail ld_sess8 on ld_sess8.labelID = o_sess8.labelID and ld_sess8.langId = 1 and ld_sess8.eid = 107 
    left join tbloption o_sess9 on o_sess9.id = session_cust.option9 and  o_sess9.sid = 105
    left join tblLabelDetail ld_sess9 on ld_sess9.labelID = o_sess9.labelID and ld_sess9.langId = 1 and ld_sess9.eid = 107 
    where session.sID=105  and session.tStamp >= 'Sep  1 2014 12:00AM' and session.tStamp < 'Dec 12 2014 12:00AM'   
    order by session.tStamp, session.ID
    Is there a way , where i can simplify the joins with tbloption and tblLabelDetail and get my o/p in optimal time.
    Regards 

    I have headed towards another approach ie. using unpivot and then pivot.
    First i am converting option1-option9 into column , then doing  PIVOT to get back the same record . But issue is that when i am doing pivoting i am getting NULL values.
    My query is :
    select * into #t1  from
    select ID
    , option1
    , option2
    , option3
    , option4
    , option5
    , option6
    , option7
    , option8
    , option9
    from vCustomConsumer
    where sid=105
    and sessionYM = 1412 
    ) SourceTable
    UNPIVOT
       optionID FOR Col IN
        (option1 
    ,option2
    ,option3 
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9 )
    ) AS unpvt
    select t.ID,t.optionID,t.col,cast(ld.text as varchar(max)) as text into #t2
    from #t1 t
    left outer join tbloption o on o.ID =  t.optionID
    left outer join tblLabelDetail ld on ld.labelID = o.labelID and ld.langID=1 
    order by ID,col
    select ID,option1 
    ,option2
    ,[option3]
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9
    from
    select ID,optionID,col,text
    from #t2
    )up
    pivot 
    min(text)for col in 
    (option1 
    ,option2
    ,[option3]
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9
    )as pvt
    In my last query where i am using pivot, i am getting NULL values. When i check the data in temp table #t2 , it exists perfectly . But when pivoting i dont understand why it is returning most of the NULL values. I am getting data for only one column in single
    row.
    Below are some rows from result set finally obtained after pivoting :
    ID
    option1
    option2
    option3
    option4
    option5
    option6
    option7
    option8
    option9
    62949026
    NULL
    0 to 200 seconds
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    62966000
    NULL
    NULL
    4
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    62966032
    NULL
    NULL
    4
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    63090372
    NULL
    NULL
    NULL
    NULL
    EN
    NULL
    NULL
    NULL
    NULL
    63090375
    NULL
    NULL
    NULL
    NULL
    EN
    NULL
    NULL
    NULL
    NULL
    Thanks,

  • How to get the results in one line

    Hi
    if i use the script below i get the name of path and then : and in next line i get the results.is there a way to get the results from every path after the : and not in the next line?
    another question - is there a way that the script will not show the server name on every path?
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter
    THC

    If you take you script and pipe it to get member, it will give you a list of various script properties.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | get-member
    You will see that the object type returned by "Get-Counter" is Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet.
    TypeName:
    Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet
    Name MemberType Definition
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    CounterSamples Property Microsoft.PowerShell.Commands.GetCounter.Perfo...
    Timestamp Property datetime Timestamp {get;set;}
    Readings ScriptProperty System.Object Readings {get=$strPaths = ""...
    You can try grabbing different properties, and they will print out differently, displaying the data on the same line in some cases. For example, pipe your output to a "foreach-object" block, and then for each object print out the CounterSamples property.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | foreach-object { ($_).CounterSamples }
    This should all print on one line now. However, you also asked if there was a way to not have the server print out on every line. The way to control the format of these outputs is to use the "format-table" cmdlet. So you would pipe your output to format-table
    and then give it various options. This is how you would pipe it (without any options).
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | object { ($_).CounterSamples | format-table }#OR USE YOUR ORIGINAL CODE(Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | format-table }
    Now, it's up to you to give format-table the options you want. With no options, output will look unchanged. To see what options are available to you, use get-help.
    get-help format-table
    I hope this helps!
    Thank for all the info...

  • Sql*loader - load data in table with multiple condition

    Hi,
    I have oracle 9i on Sun sloaris and i need to load data in one of oracle table using sql*loader with conditional column data.
    My table is like:
    Load_table
    col1 varchar2(10),
    col2 varchar2(10),
    col3 varchar2(10),
    Now i have to load data like:
    If col2 = US1 then col3 = 'AA'
    If col2 = US2 then col3 = 'BB'
    If col2 = US3 then col3 = 'CC'
    How can i load this data in table using sql*loader?
    Thanks,
    Pora

    Hi
    it is a half-solution.
    You have to:
    1. open file
    2. take a line
    3. split the line into values (using substring to)
    4. check condition (01 or 02)
    5. do a proper insertion
    Good Luck,
    Przemek
    DECLARE
    v_dir VARCHAR2(50) := 'd:/tmp/'; --directory where file is placed
    v_file VARCHAR2(50) := 'test.txt'; -- file name
    v_fhandle UTL_FILE.FILE_TYPE; ---file handler
    v_fline VARCHAR2(906); --file line
    v_check VARCHAR2(50);
    BEGIN
    v_fhandle := UTL_FILE.FOPEN(v_dir, v_file, 'R'); --open file for read only
    LOOP -- in the loop
    UTL_FILE.GET_LINE( v_fhandle , v_fline); -- get line by line from file
    if (substr(v_fline,17,2) = '01') then --check the value
    INSERT INTO ... -- Time_in
    else
    INSERT INTO ... -- Time_out
    end if;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN UTL_FILE.FCLOSE( v_fhandle );
    END;

  • SQL*Loader with multiple files

    Gurus,
    I search the documentation and this forum and haven't found a solution to my issue yet...
    I am not expert of SQL*Loader. I have used SQL*Loader to copy from one file to a table many times. But I have not copied multiple files into one table especially with different names.
    More specifically....
    I need to load data from multiple files into a table. But the file names will be different each time. A file will be created every hour. The file name will consist of the root file name appended by a time stamp. For example, a file created on 10/07/2010 at 2:15 P.M. would be filea100720101415.txt while a file created on 10/08/2010 at 8:15 A.M. would be filea100820100815.txt. All the files will be in one directory.How can I load the data from the files using SQL*Loader?
    My database: Oracle 10g Release 2
    Operating System: Windows 2003 Server
    Please assist.
    Robert

    sect55 wrote:
    Gurus,
    I search the documentation and this forum and haven't found a solution to my issue yet...
    I am not expert of SQL*Loader. I have used SQL*Loader to copy from one file to a table many times. But I have not copied multiple files into one table especially with different names.
    More specifically....
    I need to load data from multiple files into a table. But the file names will be different each time. A file will be created every hour. The file name will consist of the root file name appended by a time stamp. For example, a file created on 10/07/2010 at 2:15 P.M. would be filea100720101415.txt while a file created on 10/08/2010 at 8:15 A.M. would be filea100820100815.txt. All the files will be in one directory.How can I load the data from the files using SQL*Loader?
    My database: Oracle 10g Release 2
    Operating System: Windows 2003 Server
    Please assist.
    RobertToo bad this isn't in *nix, where you get a powerful shell scripting capability. 
    That said, here is the core of the solution .... you will also need a way to identify files that have been processed vs. new ones. Maybe rename them, maybe move them. But with this sample you can see the basics. From there it is really an issue of DOS scripting, which would better be found by googling around a bit.
    cd c:\loadfiles
    FOR %%datfile IN (*.txt) DO SQLLDR CONTROL=sample.ctl, LOG=sample.log, BAD=baz.bad, DATA=%%datfileTry googling "dos scripting language". You'll find lots of tutorials and ideas on "advanced" (well, as advanced as DOS gets) techniques to solve your problem.
    Edited by: EdStevens on Dec 1, 2010 5:03 PM

  • Joins with multiple fact tables

    Hi Experts,
    i have one doubt in joins
    we have two dimensions D1 and D2,
    D1 is having A1 and A2 columns
    D2 is having B1 and B2 columns
    two facts F1 and F2 these are joined like D1 to F1 D1 to F2 and D2 to F1, D2 to F2
    D1----->F1
    D1------>F2
    D2-------->F1
    D2-------->F2
    if i selected A1 and B1 in a request from which FACT table will get the data and why can you please explain
    please help me
    reg,
    Jell

    Hi All,
    I have a similar requirement where I have 4 multiple fact tables and we can't combine all those facts into one single fact table. In that case how can a query work with multiple common and uncommon dimensions and measures from multiple fact tables, if it doesn't work that way - can you please explain how can we expect a query to work with multiple fact tables.
    For eg: D1– Dim
    D2 – Dim
    D3 – Dim
    D4 – Dim
    F1 –Fact
    F2 – Fact
    F3 – Fact
    D1 -> F1
    D2 -> F1,F2
    D3 -> F2
    D4 -> F1, F3
    In this case if we want to query from D1,D2,D3, F1, F2 or D1,D2,D3,D4,F1,F2,F3. Kindly please explain how it can be modeled in BMM or what are the limitations. I have done with two fact tables in past and didn't had issues but this is kind of a vast implementation. Your help is appreciated.

  • SQL Dealing with multiple choice answers in a DB with no unique identifier

    I am working with a Database that has forms set up with multiple select fields.  As seen below, (Question_ID 2533) the Patient_ID, Visit_ID, and Question_ID are the same and there are 3 different answers that were chosen.  I am trying to figure
    out how to seperate these Multiple answers so I can use SSRS to pull them into seperate fields. I believe I know how to use SSRS to pull the data after I have differentiated each answer. I need help with the SQL code...
    Patient_ID   Visit_ID   Form_ID   Question_ID   Answer_ID     Answer
    124            1685        164          2533             1490             
    Muscle pain
    124            1685        164          2533             1492             
    Weight loss
    124            1685        164          2533             1494            
     Shoulder joint pain
    124            1685        164          2534            
    678                Good
    124            1685        164          2535            
    678                Good

    I was able to get the unique identifier by creating a new table using the ROW_NUMBER()OVER and PARTITION BY Functions.  Then I was able to identify each answer of the multiple choice fields.  Here is the full code.
    CREATE TABLE Multiple_Answer(
     Patient_ID INT,
     Visit_ID INT,
     Visit_Date DateTime,
     Form_ID INT,
     Form_Name nvarchar(255),
     Question_ID INT,
     Question_Name nvarchar(1000),
     Answer_ID INT,
        Answer  nvarchar(1000),
        Multiple_Answer INT)
        INSERT INTO Medred_Reporting.dbo.Multiple_Answer
               ([Patient_ID]
               ,[Visit_ID]
               ,[Visit_Date]
               ,[Form_ID]
               ,[Form_Name]
               ,[Question_ID]
               ,[Question_Name]
               ,[Answer_ID]
               ,[Answer]
               ,[Multiple_Answer])
    SELECT        Patients.Patient_ID, Patient_Visits.Visit_ID, Patient_Visits.Visit_Date, Forms.Form_ID, Forms.Form_Name, Questions.Question_ID, Questions.Question_Name, Answers.Answer_ID,
                             Answers.Answer,
                             ROW_NUMBER()OVER
                             (PARTITION BY Patients.Patient_ID, Patient_Visits.Visit_ID,Forms.Form_ID,Questions.Question_ID
                             ORDER BY Questions.Question_ID)
                             AS Multiple_Answer
    FROM            Patient_Visits INNER JOIN
                             Patients ON Patient_Visits.Patient_ID = Patients.Patient_ID INNER JOIN
                             User_Visit_REL ON Patient_Visits.Visit_ID = User_Visit_REL.Visit_ID INNER JOIN
                             Users ON User_Visit_REL.User_ID = Users.User_ID INNER JOIN
                             Visit_Question_Answer_REL ON User_Visit_REL.User_Visit_ID = Visit_Question_Answer_REL.User_Visit_ID INNER JOIN
                             Symptom ON Visit_Question_Answer_REL.Symptom_ID = Symptom.Symptom_ID INNER JOIN
                             Question_Answer_REL ON Symptom.Question_Answer_ID = Question_Answer_REL.Question_Answer_ID INNER JOIN
                             Answers ON Question_Answer_REL.Answer_ID = Answers.Answer_ID INNER JOIN
                             Form_Question_REL ON Question_Answer_REL.Form_Question_ID = Form_Question_REL.Form_Question_ID INNER JOIN
                             Questions ON Form_Question_REL.Question_ID = Questions.Question_ID INNER JOIN
                             Protocol_Form_REL ON Form_Question_REL.Protocol_Form_ID = Protocol_Form_REL.Protocol_Form_ID INNER JOIN
                             Forms ON Protocol_Form_REL.Form_ID = Forms.Form_ID

  • SQL Script - error in executing the select with multiple conditions

    Hi gurus,
    I'm having trouble in the command syntax below:
    SELECT * FROM "TEST_RVS"."VH_TEST"  WHERE   "AUFNR" = 20210807 AND  "BWART" = 101.
    WHAT IS THE CORRECT SYNTAX WHERE TO CONDITION WITH MULTIPLE FIELDS?
    Thanks !

    What is the error you are getting?  Did you try wrapping the values with quotes?
    SELECT * FROM "TEST_RVS"."VH_TEST"  WHERE   "AUFNR" = '20210807' AND  "BWART" = '101'.
    Cheers,
    Rich Heilman

Maybe you are looking for

  • Sync iPod nano 2nd generation

    I have some audio files taped from a live lecture in mp3 format in my iTunes library. I cannot sync/ transfer to my 2GB iPod nano. I have not been able to figure out why. It gives me the info that my files are not in a format that iPod nano supports,

  • Interactive Reports using Collections

    I need to prepare queries dynamically using PLSQL on apex 3.2; Since interactive reports are currently supported only using SQL queries , I am storing the results in a collection and then retrieving the results from the collection. I got this working

  • Trusted User Authentication

    Hi, Our solution currently offers three SSID's.  One corporate SSID for trusted users (employees) with trusted (company managed) devices, one guest SSID for external guests who are not trusted and use non-trusted devices and then a third "guest" SSID

  • Installing error 10.4

    im trying to install 10.4 on a new HD and it keeps failing, i have tried diffrent ram, incuding stock ram. it gets to language German and a error occors and it says please try installing agin, with a restart botton at the bottom. plea

  • Software update cannot be installed on this disk

    trying to install office update and message says a version of the software required to install update was not found on this volume??? Help any body regards barry