Comparision of a row with multiple criteria

Hi All,
I have below source table which gives me CUTSOMER_ID, FIRST_NAME, LAST_NAME, DOB, ZIPCODE and D_ID. Now i need to compare it with target, which gives me same columns. below are my comparision criteria.
1. Compare CUSTOMER_ID, if it matches with any of the target CUSTOMER_ID mark the row with F_FLG = M
2. If CUSTOMER_ID does not match, then compare the row with target based on compbination of (FIRST_NAME, LAST_NAME, DOB and ZIPCODE). If this combination of columns matches with any of the row from target, then marked row with F_FLG = M
3. If CUSTOMER_ID and combination of (FIRST_NAME, LAST_NAME, DOB and ZIPCODE) column does not match with any of the target row, the use another set of column. compare the row with target based on compabination of (FIST_NAME, LAST_NAME, D_ID). If this combinatio of column matches with ay of the row from target, then marked row with F_FLG = M
4. If any of the above criteria does not match, then mark the row with F_FLG = N
CUSTOMER_ID     FIRST_NAME     LAST_NAME     DOB          ZIPCODE          D_ID
101          GEORGE          MAC          15-APRIL-2009     12345          23456
102          MICLE          DON          10-MARCH-1980     45678          29087
103          VIJAG          UJIK          01-JAN-1950     67890          27689
104          BONY          PANDA          03-MAY-1961     12345          27878These combinations should be performed once at a time. If it satisfies the first criteria, we do not need to check for remaining 3. If it does not match with 1 then perform 2 if matches flag the row and if not, go for 3rd criteria. if matches them mark with M else N
Below is the Target rows.
CUSTOMER_ID     FIRST_NAME     LAST_NAME     DOB          ZIPCODE          D_ID
101          ADA          MICO          15-APRIL-2009     12345          23456
999          MICLE          DON          10-MARCH-1980     45678          23567
888          VIJAG          UJIK          01-APR-1999     89897          27689
777          AAA          BBB          03-MAY-1961     87687          12345Here,
for 1st row, CUSTOMER_ID matches with source and target, flag the row with valye = M
for 2nd row, CUSTOMER_ID (102) does not match with Target. but combination of (FIRST_NAME, LAST_NAME, DOB and ZIPCODE) matches, flag the row with value = M
for 3rd row, CUSTOMER_ID (103) and combination of (FIRST_NAME, LAST_NAME, DOB and ZIPCODE) does not match, but combination of (FIRST_NAME, LAST_NAME and D_ID) matches, flag the row with value = M
for 4th row, none of the combination matches with Target, flag the row with value = N
Output should be
CUSTOMER_ID     FIRST_NAME     LAST_NAME     DOB          ZIPCODE          D_ID     F_FLG
101          GEORGE          MAC          15-APRIL-2009     12345          23456     M
102          MICLE          DON          10-MARCH-1980     45678          29087     M
103          VIJAG          UJIK          01-JAN-1950     67890          27689     M
104          BONY          PANDA          03-MAY-1961     12345          27878     N

Try this one
WITH data1 AS
     (SELECT 101 customer_id, 'GEORGE' first_name, 'MAC' last_name, TO_DATE ('15-APRIL-2009', 'dd-mon-yyyy') dob,
             12345 zipcode, 23456 d_id
        FROM DUAL
      UNION ALL
      SELECT 102 customer_id, 'MICLE' first_name, 'DON' last_name, TO_DATE ('10-MARCH-1980', 'dd-mon-yyyy') dob,
             45678 zipcode, 29087 d_id
        FROM DUAL
      UNION ALL
      SELECT 103 customer_id, 'VIJAG' first_name, 'UJIK' last_name, TO_DATE ('01-JAN-1950', 'dd-mon-yyyy') dob,
             67890 zipcode, 27689 d_id
        FROM DUAL
      UNION ALL
      SELECT 104 customer_id, 'BONY' first_name, 'PANDA' last_name, TO_DATE ('03-MAY-1961', 'dd-mon-yyyy') dob,
             12345 zipcode, 27878 d_id
        FROM DUAL),
     data2 AS
     (SELECT 101 customer_id, 'ADA' first_name, 'MICO' last_name, TO_DATE ('15-APRIL-2009', 'dd-mon-yyyy') dob,
             12345 zipcode, 23456 d_id
        FROM DUAL
      UNION ALL
      SELECT 999 customer_id, 'MICLE' first_name, 'DON' last_name, TO_DATE ('10-MARCH-1980', 'dd-mon-yyyy') dob,
             45678 zipcode, 23567 d_id
        FROM DUAL
      UNION ALL
      SELECT 888 customer_id, 'VIJAG' first_name, 'UJIK' last_name, TO_DATE ('01-APR-1999      ', 'dd-mon-yyyy') dob,
             89897 zipcode, 27689 d_id
        FROM DUAL
      UNION ALL
      SELECT 777 customer_id, 'AAA' first_name, 'BBB' last_name, TO_DATE ('03-MAY-1961      ', 'dd-mon-yyyy') dob,
             87687 zipcode, 12345 d_id
        FROM DUAL)
SELECT customer_id, first_name, last_name, dob, zipcode, d_id, f_flg
  FROM (SELECT customer_id, first_name, last_name, dob, zipcode, d_id, f_flg,
               ROW_NUMBER () OVER (PARTITION BY customer_id ORDER BY f_flg) rn
          FROM (SELECT DISTINCT d.customer_id, d.first_name, d.last_name, d.dob, d.zipcode, d.d_id,
                                CASE
                                   WHEN d.customer_id = d2.customer_id
                                      THEN 'M'
                                   WHEN d.first_name = d2.first_name
                                   AND d.last_name = d2.last_name
                                   AND d.dob = d2.dob
                                   AND d.zipcode = d2.zipcode
                                      THEN 'M'
                                   WHEN d.first_name = d2.first_name AND d.last_name = d2.last_name AND d.d_id = d2.d_id
                                      THEN 'M'
                                   ELSE 'N'
                                END f_flg
                           FROM data1 d, data2 d2
                       ORDER BY 1, DECODE (f_flg, 'M', 1)))
WHERE rn = 1Regards,
Mahesh Kaila

Similar Messages

  • Counting rows with multiple criteria

    I know this is a silly beginner question, but is there an easy way to count the number of rows in a table which match criteria based on different columns (sort of a countif with multiple criteria). For example, if Column A in a table has "All, Some, None" responses and Column B has "Main, Off" responses, is there an easy way to count the number of rows in which Column A has All and Column B has Off?

    Neondiet wrote:
    From an intellectual and philosophical view I agree with you. But from a practical view what I really want to do is just use one application for my spreadsheet tasks, not jump back and forth because one sheet I share with MS Windows users, and another with Numbers users, and another with OS X users who don't have Numbers or Excel but do have NeoOffice. Maybe I have to settle for that though.
    Yeah... this kind of situation stinks. Its like needing to writing software that will run on both Macs and PCs.
    Anyway, I've followed the advise in this forum and resorted to using a hidden column with concatenated values to solve my own problem, though it does seem like a bit of a hack compared to managing a single formula in a single cell. Horses for courses I suppose.
    jaxjason has posted a very elegant pivot table like solution that utilizes this technique. See http://www.numberstemplates.com/forums/showthread.php?t=36
    Btw, from what I've read on the net to date, SUM (in Excel) with an array formula answers the original authors problem of counting occurrences of values, not SUMPRODUCT; which I believe sums up the contents of cells in a range, if cells in other ranges match specific criteria.
    Yes, if you use the '*' (as indicated above) then SUM() is sufficient though SUMPRODUCT() will work as it degenerates to SUM when there is only one argument. If you use two arrays as arguments (like: = SUMPRODUCT((A1:A4="All"), (B1:B4="Off")), then SUMPRODUCT() is necessary. Here's my understanding of how it works (I hope your able to follow my abuse of algebraic techniques):
    =SUM((A1:A4="All") * (B1:B4="Off"))
    expanding the array expressions...
    =SUM((A1="All", A2="All", A3="All", A4="All") * (B1="Off", B2="Off", B3="Off", B4="Off"))
    at this point Excel computes the equality expressions, for example...
    =SUM((TRUE, FALSE, TRUE, FALSE) * (TRUE, TRUE, FALSE, FALSE))
    expanding the array multiplication...
    =SUM((TRUE * TRUE, FALSE * TRUE, TRUE * FALSE, FALSE * FALSE))
    Excel, apparently, then, when forced to multiply Boolean values, maps TRUE -> 1 and FALSE -> 0...
    =SUM((1 * 1, 0 * 1, 1 * 0, 0 * 0))
    performing the multiplications...
    =SUM((1, 0, 0, 0))
    summing...
    =1 + 0 + 0 + 0
    resulting...
    =1
    I'm afraid, now, if I continue any further, Yvan will chastise me.

  • Table Rows with Multiple Conditions Not Showing Up in RH

    Hi everyone,
    I'm currently evaluating TCS2 (Framemaker 9 and RoboHelp 8 on Windows XP) and have come across the following issue:
    One of our FrameMaker source files contains a table in which one of the rows has multiple conditions applied. When one of the conditions is shown in Framemaker, and the others are hidden, the row is displayed in Framemaker as expected. However, when the file is then imported or linked into Robohelp, the same table row vanishes, even though the Apply FrameMaker Conditional Text Build Expression check box is selected in the Framemaker Conversion Settings > Other Settings screen. This only appears to affect table rows - when paragraph text is tagged with the same conditions, it is imported correctly into RoboHelp.
    For example, when Condition B is shown and Condition A is hidden in the Framemaker file, the content appears like this in Frame:
    Unconditional
    Unconditional
    Condition A and Condition B applied
    Condition A and Condition B applied
    Condition B applied
    Condition B applied
    Paragraph text with Condition A and Condition B applied.
    Paragraph text with Condition B applied.
    When the same file is imported into RoboHelp, the row with both conditions applied is absent from the table:
    Unconditional
    Unconditional
    Condition B applied
    Condition B applied
    Paragraph text with Condition A and Condition B applied.
    Paragraph text with Condition B applied.
    Installing patches 8.0.1 and 8.0.2 did not resolve the issue (and actually caused other, unrelated issues) and I see the same behavior regardless of whether I import or link the FrameMaker document.
    Has anyone else seen this issue? Any help would be much appreciated.
    Thanks
    DaveB

    It just seems that the items I select as align to top in the
    property inspector should force the items to the top of their
    cells, unless I'm missing something.

  • Table row with multiple row

    Hi All,
    I am using NWDS 2004
    I want to have a table with multiple rows in a row.
    Can any one help ?
    Thanks

    hi Akhilesh,
    Use tree table for your requirement.
    [Tree Table Tutorial|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/de59f7c2-0401-0010-f08d-8659cef543ce]
    Hope this helps!
    Monalisa

  • Report Record Row with multiple color conditionaly

    Dear Friend,
    i am using Apex 3.2 ver.
    i want to display report record row with colour .
    i want to display reoport row color blue if INVOICE_TYPE column is 'I' and RED if INVOICE_TYPE is 'C' .
    select
    am.ID,
    am.INVOICE_NO,
    am.INVOICE_NO as invoice,
    am.SBU_CODE,
    am.INVOICE_TYPE,
    am.INVOICE_DATE,
    am.AGENT_CODE,
    am.NO_OF_PAX,
    am.ADDL_FIELD5
    from "AR_INVOICE_MAS"  amHow can i disply row record conditionaly color ful .
    Thanks
    Edited by: Vedant on Oct 10, 2012 11:05 PM
    Edited by: Vedant on Oct 10, 2012 11:14 PM

    Dear Jary,
    Thanks to reply me.
    i have follow your link and font color display but bg color not display.
    now i have change in code
    select
    am.ID,
    case       when am.INVOICE_TYPE = 'C' then 'BLUE'
               when am.USER_ENTER_AMT = sum(al.NET_AMT) then 'RED'
                end the_color,
    am.INVOICE_NO,
    am.INVOICE_NO as invoice,
    am.SBU_CODE,
    am.INVOICE_TYPE,
    am.INVOICE_DATE,
    am.AGENT_CODE,
    am.NO_OF_PAX,
    am.ADDL_FIELD5,
    NVL(sum(al.NET_AMT),0) AS SUM,
    NVL(am.USER_ENTER_AMT,0.00) AS CONTROLSUM
    from "AR_INVOICE_MAS"  am ,AR_INVOICE_DTL al WHERE am.invoice_no=al.invoice_no(+)
    group by am.ID,am.invoice_no,am.SBU_CODE,am.invoice_type,am.invoice_date,am.agent_code,
    AM.NO_OF_PAX, am.ADDL_FIELD5,am.USER_ENTER_AMT Here i want to display in red below condition but it's not working.
    when am.USER_ENTER_AMT = sum(al.NET_AMT) then 'RED'How can i display Record in RED which record does not varify below condition
    when am.USER_ENTER_AMT = sum(al.NET_AMT) then 'RED'
    How can i do this.
    Thanks

  • Single Update command to update multiple rows with multiple rows

    Hi Gurus!
    Can I update table A with a result set of table b (multiple rows returns) where a.c1 = b.c1
    regards,
    SH

    As Joel mentioned this update will update all rows in a table based on another one:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    Also, any rows that don't match the select criteria will get updated to null. This could be very bad depending on what you want to do.
    To update a subset of tableA with data from tableB:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    where exists (select 1 from tableB where tableA.ID = tableB.ID)

  • How to return one ROW with Multiple value seperated by Colon in a SQL Query

    Hi,
    I have a SQL query as mentioned.
    select deptno
      from deptI want to mofidfy this query, so that this should return me department list with colon delimeted in one ROW.
    10:20:30:40.......Thanks,
    Deepak

    In 10g:
    select rtrim(xmlagg(xmlparse(content deptno || ':')).getstringval(), ':') data
    from   dept;
    DATA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    10:20:30:40with apologies for the abuse of XML...

  • Help Creating Dynamic Stacked Column Chart with Multiple Criteria

    Hi all. Im new here and hoping you can help.  I have a dashboard Im trying to rebuild from scratch (our computer had a meltdown and we lost all our files). I did not build the dashboard initially so Im trying to recreate it from the flash file we were able to recover. I have come across a chart that I just cannot figure out how to do.  I can figure out how to write an array in the Excel sheet that pulls the data into a table the way I need it to be but found out after I wrote that that Xcelcius doesn't support arrays so all my data disappears when I go into preview mode (which is especially frustrating since I can see the chart working fine in design mode).  Anyway this is what the data table looks like
    Month         Year            Company      Positive #          Negative #         Neutral #          Positive %       Negative %      Neutral %
    October      2011            CompanyA      1234                1234                 1234                 10                    10                    10
    October      2011            CompanyB      1234                1234                 1234                 10                    10                    10
    October      2011            CompanyC      1234                1234                 1234                 10                    10                    10
    October      2011            CompanyD      1234                1234                 1234                 10                    10                    10
    November  2011            CompanyA      1234                1234                 1234                 10                    10                    10
    November  2011            CompanyB      1234                1234                 1234                 10                    10                    10
    November  2011            CompanyC      1234                1234                 1234                 10                    10                    10
    November  2011            CompanyD      1234                1234                 1234                 10                    10                    10
    December  2011            CompanyA      1234                1234                 1234                 10                    10                    10
    December  2011            CompanyB      1234                1234                 1234                 10                    10                    10
    December  2011            CompanyC      1234                1234                 1234                 10                    10                    10
    December  2011            CompanyD      1234                1234                 1234                 10                    10                    10
    The original chart was built so that you would choose the month from a combo box and then the company names would show up along the X axis with their % amounts shown in the stacked column.  I know how to make a combo box work and I know how to make a stacked column chart work with static data.  I cannot for the life of me figure out how to get it to work so that when you choose the month from the combo box it filters the data.  I've tried filtered rows but I'm just missing some information that makes it work and I can't figure out what that information is.  It has to be able to get the month/year combo from the combo box and then go to the table, filter it by month and year and then create a multi-row table of data with just the company and the percent values.  Any help would be greatly appreciated!

    Which connection you are using?
    IF quite difficult if you are working under static data.

  • SQL Question (Select rows with multiple records)

    Hello Gurus,
    I am learning SQL and have a question. Thanks for your time and help.
    I have 2 tables TABLE_AA and TABLE_BB. Both tables have two columns ID, DATA.
    TABLE_AA is connected to TABLE_BB through ID field (TABLE_AA.AA_DATA = TABLE_BB.BB_DATA)
    TABLE_AA
    ~~~~~~~
    AA_ID______AA_DATA
    ~~~~~~~~~~~~~~~~
    1111_______XXXX
    2222_______QQQQ
    3333_______ZZZZZ
    4444_______PPPPP
    ~~~~~~~
    TABLE_BB
    ~~~~~~~
    BB_ID BB_DATA
    ~~~~~~~~~~~~~~~~
    1111_______AAAA
    2222_______BBBB
    3333_______CCCC
    3333_______DDDD
    4444_______EEEE
    I am looking to get those AA_ID values that have multiple in TABLE_BB for their parent reference in TABLE_BB.
    So, from the above example, the sql should return the following as AA_ID 3333 has more than 1 reference value in BB_ID
    AA_ID_____BB_ID
    ~~~~~~~~~~
    3333______CCCC
    3333______DDDD

    Hi,
    It's working fine. !!
    14:10:05 topgun>With a As
    14:10:06   2   (
    14:10:06   3   Select 1111 c1, 'AAAA' c2 From dual Union All
    14:10:06   4    Select 2222 ,   'BBBB'    From dual Union All
    14:10:06   5    Select 3333 ,   'CCCC'    From dual Union All
    14:10:06   6    Select 4444 ,   'DDDD'    From dual
    14:10:06   7   ), b As
    14:10:06   8    (
    14:10:06   9    Select 1111 c1,'AAAA' c2 From dual Union All
    14:10:06  10   Select 2222 ,  'BBBB'    From dual Union All
    14:10:06  11   Select 3333 ,  'CCCC'    From dual Union All
    14:10:06  12   Select 3333 ,  'DDDD'    From dual Union All
    14:10:06  13   Select 4444 ,  'EEEE'    From dual
    14:10:06  14    )
    14:10:06  15   Select c1,
    14:10:06  16           c2
    14:10:06  17     From
    14:10:06  18       (
    14:10:06  19       Select a.c1,
    14:10:06  20              b.c2,
    14:10:06  21             Count(*) over (Partition By a.c1 Order By a.c1) cnt
    14:10:06  22      From  a,
    14:10:06  23             b
    14:10:06  24       Where a.c1 = b.c1
    14:10:06  25        )
    14:10:06  26   Where cnt = 2;
            C1 C2
          3333 CCCC
          3333 DDDD- Pavan Kumar N

  • Search with multiple criteria

    I have searched high and low on the internet o find a way to
    do a search through multple fields but the more I lookthe more i
    get confused. here is the problem. i want to do a search where the
    user can input a data element and select the matching type and
    display he results.below is the code that i have for my search
    page, but I am confused about the more important parts of the fom -
    the actual search variables.
    If you look t the code below you see that I have a test field
    named "recordID" and a drop down list named "select".
    I want to dispay the results in which 'recordID' looks in
    table thatis equal to 'select'.
    an example of what I want is at the following link.
    http://www.phpscriptsearch.com/

    DizzDizzy wrote:
    > I went to
    http://www.webassist.com/professional/products/productdetails=
    =2Easp?PID=3D117&CouponID=3Dss2008&RID=3D590&WAAID=3D92
    > but i could not find the solution there
    Hi Dizz:
    Under the banner you'll find links for Overview, Features,
    System=20
    Requirements, Support. When you click on the Features link,
    the MooFX=20
    Accordian javascript class runs to update the content on the
    page. The=20
    bullet points are clickable to similarly update the content
    on the page. =
    Click on the bullet point "Pro search and sort enhancements"
    and read=20
    the paragraph at the bottom under the screen shots:
    Sophisticated search capabilities
    DataAssist integrates the advanced search functionality
    previously=20
    available in Database Search. Now you can combine advanced
    Google-style=20
    keyword searches (across multiple database columns) with
    price, date or=20
    number ranges =96 all without coding.
    Please take a look at the feature tour:
    http://www.webassist.com/professional/products/featuretour/media_117.asp
    As for the Prof's requirements, the form submits two values,
    a recordID=20
    and a selection to either search by company or by store
    number.
    If Prof has a table named company and another named store
    number, the=20
    way you'd search these tables would be to have another table
    that=20
    contains the selectcategories with a column containing the
    values=20
    "company" and "storeNumber" along with ID columns that relate
    to a=20
    categoryID column in the companies table and the storeNumber
    column in=20
    the Stores table. Using this relationship Prof can create a
    reccordset=20
    on his results page that returns the values using an INNER
    JOIN to=20
    combine the tables in the recordset. Similarly by
    constructing the=20
    relationships properly as to his records (let's say he's
    searching 45RPM =
    singles - anybody remember those thingies?) His company table
    can have=20
    an ID column that references his product table where a
    companyID is=20
    stored. Again, a JOIN statement is used to include the
    product=20
    information, including the ProductID in the Recordset.
    Similarly for the =
    Stores table, again, the Products table has a column that
    identifies the =
    store that carries that productID. If more than one store
    carries the=20
    product, the column should be a storesID column that
    references a=20
    ProductStores table which references the stores that carry
    the product=20
    by a common ID. Again, using the JOIN (this recordset query
    would get=20
    complex) the necessary data can be returned.
    The DataAssist Search Server Behavior applies a sophisticated
    WHERE=20
    clause to the recordset. so that the requested records can be
    returned=20
    to the page. Prof is not needing a tool to build database
    management, so =
    I can see his point... but if this is something you do
    regularly,=20
    DataAssist will pay for itself over and over in time saved.
    And WebAssist is conducting a 50% off sale through next
    Friday, so it's=20
    a good time to get on board. Here's a link to the discount
    page for all=20
    the products:
    http://www.webassist.com/professional/products/productresults.asp?CouponI=
    D=3Dss2008&RID=3D590&WAAID=3D92=20
    enthusiastically,
    mark haynes.

  • Create Dynamic groups with multiple criteria

    Hello,
    I want to create a dynamic group of sql computers in a particular domain.
    What should be the criteria?
    System creates this:
    ((object is windows computer and (dns domain name equals contoso.com) and true) OR (object is SQL computers and (display name matches wildcard *) and True))
    How can I set to below?
    ((object is windows computer and (dns domain name equals contoso.com) and true)
    AND (object is SQL computers and (display name matches wildcard *) and True))
    Thanks

    Use
    the link that Blake already supplied to the site of Jonathan and use this XML part.
    Replace the XXXXXXXXXX of course with the name of your class/group. Don't forget to add a reference to the SQL Server Core Library Management Pack. 
    <RuleId>$MPElement$</RuleId>
    <GroupInstanceId>$MPElement[Name="XXXXXXXXXX"]$</GroupInstanceId>
    <MembershipRules>
    <MembershipRule>
    <MonitoringClass>$MPElement[Name="Windows!Microsoft.Windows.Computer"]$</MonitoringClass>
    <RelationshipClass>$MPElement[Name="SC!Microsoft.SystemCenter.ComputerGroupContainsComputer"]$</RelationshipClass>
    <Expression>
    <Contains>
    <MonitoringClass>$MPElement[Name="MicrosoftSQLServerLibrary!Microsoft.SQLServer.DBEngine"]$</MonitoringClass>
    <Expression>
    <RegExExpression>
    <ValueExpression>
    <HostProperty>
    <MonitoringClass>$MPElement[Name="Windows!Microsoft.Windows.Computer"]$</MonitoringClass>
    <Property>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/DNSName$</Property>
    </HostProperty>
    </ValueExpression>
    <Operator>MatchesRegularExpression</Operator>
    <Pattern>domain.(dev|net)/Pattern>
    </RegExExpression>
    </Expression>
    </Contains>
    </Expression>
    </MembershipRule>
    </MembershipRules>
            </Configuration>

  • Transpose row with multiple data into 3 columns / Excel Macros

    Hi everyone, can you please help me with my manual intervention of transposing column data to row format?
    Sample
    Dates
    01/01/2014
    01/02/2014
    01/03/2014
    01/04/2014
    01/05/2014
    01/06/2014
    01/07/2014
    01/08/2014
    01/09/2014
    01/10/2014
    01/11/2014
    Name1
    Value 1
    Value 2
    Value 3
    Value 4
    Value 5
    Value 6
    Value 7
    Value 8
    Value 9
    Value 10
    Value 11
    Name2
    Item1
    Item2
    Item3
    Item4
    Item6
    Item7
    Item8
    Item9
    Item10
    Name3
    Code1
    Code2
    Code4
    Code5
    Code6
    Code7
    Code8
    Code9
    Code10
    Code11
    Expected output
    NAME
    Date
    DATA
    Name1
    01/01/2014
    Value 1
    Name1
    01/02/2014
    Value 2
    Name1
    01/03/2014
    Value 3
    Name1
    01/04/2014
    Value 4
    Name1
    01/05/2014
    Value 5
    Name1
    01/06/2014
    Value 6
    Name1
    01/07/2014
    Value 7
    Name1
    01/08/2014
    Value 8
    Name1
    01/09/2014
    Value 9
    Name1
    01/10/2014
    Value 10
    Name1
    01/11/2014
    Value 11
    Name2
    01/01/2014
    Item1
    Name2
    01/02/2014
    Item2
    Name2
    01/03/2014
    Item3
    Name2
    01/04/2014
    Item4
    Name2
    01/05/2014
    Item5
    Name2
    01/06/2014
    Item6
    Name2
    01/07/2014
    Item7
    Name2
    01/08/2014
    Item8
    Name2
    01/10/2014
    Item9
    Name2
    01/11/2014
    Item10
    Name2
    01/12/2014
    Item11
    Name3
    01/01/2014
    Code1
    Name3
    01/02/2014
    Code2
    Name3
    01/03/2014
    Code3
    Name3
    01/04/2014
    Code4
    Name3
    01/05/2014
    Code5
    Name3
    01/06/2014
    Code6
    Name3
    01/07/2014
    Code7
    Name3
    01/08/2014
    Code8
    Name3
    01/09/2014
    Code9
    Name3
    01/10/2014
    Code10
    Name3
    01/11/2014
    Code11

    See my reply in
    http://www.eileenslounge.com/viewtopic.php?f=27&t=17245
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Convert multiple rows to one row with multiple columns

    Hi
    i have a table Match_1 with 2 columns 'Source' and 'target'.One source can have multiple targets and that number could be anything
    CREATE TABLE Match_1
    Source CHAR(1),
    Target CHAR(1)
    INSERT INTO Match_1 VALUES ('A', 'B');
    INSERT INTO Match_1 VALUES ('A', 'C');
    INSERT INTO Match_1 VALUES ('A', 'D');
    INSERT INTO Match_1 VALUES ('A', 'E');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'Y');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'W');
    COMMIT;
    i need to get my output in the below format
    Source     target 1     target 2     target 3     target 4          target n
    A     B          C          D               
    V     X          Y          Z          W          
    Could you please provide me the required SQL.
    REgards
    -Learnsequel

    What is your database version (4 digit) ? also my example won't be generate columns for your information:
    it will produce a result like that :
    select source, listagg(target,',') within group (order by target)
      from  match_1
      group by source;
    A     B,C,D,E
    V     W,X,X,Yps: in previos post, I wrote "with" word wrong in sql.

  • How to get the last (max of string) row with multiple records for same ID

    Hi all,
    I have a query that returns for each client ID the telephone nr, mobile phone nr, email etc... 
    There is also a column FLG_DEFAULT that indicates if the phone is the default one or not (N= changed).
    Basically what I would like my query to return is the phone number where FLG_DEFAULT = N, if this number is NULL or if FLG_DEFAULT =N does not exist I want to return the phone nr from DEFAULT_FLG = Y.
    Anyone know how I can do this in SQL? I cannot get a maximum because the format is string (e.g. +32/xxx xx xx or xxx/xx xxx xx.
    Thanks!

    ;With cte As
    (Select ClientID, PhoneNumber,
    Row_Number() Over(Partition By ClientID,
    Order By Case When FLG_DEFAULT = 'N' And PhoneNumber Is Not Null Then 1
    When DEFAULT_FLG - 'Y' Then 2 End) As rn
    From YourTableName)
    Select ClientID, PhoneNumber
    From cte
    Where rn = 1;
    Replace column names and table name with your column names and table name.
    Tom

  • How to create a search with multiple criteria

    Hi
    I've a table that contain staff information. (name, dept. position, ext, email...etc)
    I've created a search page that allow the user to search any field. The result should appear in the same page
    first i've created the form:
    enter staff First_Name:
    enter Dept. :
    select position:
    submit button
    Then I've created the record set that select all the feilds from the table, now i need a help in the criteria, This is what I used:
    SELECT *
    FROM tblstaff
    WHERE First_Name LIKE %colname% AND Dept = coldept
    for both colname and coldept
    default = 1
    runtime value = $HTTP_POST_VARS['First_Name']    -    $HTTP_POST_VARS['Dept']
    It seems to work fine when i enter all the values in the search form. but what if i left some fields empty? In other word how can I add (All in the drop down menu and accept empty value for the text search)??
    can anyone help me?

    The simplest way to do this is to add a wildcard character to the end of coldept and make the field optional.
    SELECT *
    FROM tblstaff
    WHERE First_Name LIKE %colname% AND Dept LIKE coldept%
    If the department field is left empty, it will match all departments.
    By the way, you should not be using $HTTP_POST_VARS or $HTTP_GET_VARS. It's obsolete code, and will break on a modern installation of PHP. Use $_POST and $_GET instead.

Maybe you are looking for