How to combine data from two rows into one row

I have the following sets of data. I want to find all the duplicate sets of field values. in the data below there is only one duplicate set: brenda, analyst, green.
DocID and Doc Seq combine to form the set key. FieldID I believe are consistent in that 1 is always name, 2 is job, 3 is favorite color etc. but there are up to 20 field IDs.
To tell you the truth, my client is a bit sketchy about the data and the values. I would like collapse the sets by getting all the field values into a single row. They could be in the same column, or in their own columns. This way I can then look for whatever
dups my customer seems to think that he has.
the first image is what i want (either in same column or in different columns. but they have to be in the order of the FieldID), the second is what i have. THANKS

CREATE TABLE #t (
c1 INT NOT NULL PRIMARY KEY,
c2 VARCHAR(50) NOT NULL
GO
INSERT INTO #t(c1, c2) VALUES(1, 'P1,P2,P3')
INSERT INTO #t(c1, c2) VALUES(2, 'P2,P3')
GO
-- Generate set of numbers
-- Idea from Itzik Ben-Gan
;WITH
L0 AS (SELECT 1 AS n UNION ALL SELECT 1),
L1 AS (SELECT 1 AS n FROM L0 AS a, L0 AS b),
L2 AS (SELECT 1 AS n FROM L1 AS a, L1 AS b),
L3 AS (SELECT 1 AS n FROM L2 AS a, L2 AS b),
L4 AS (SELECT 1 AS n FROM L3 AS a, L3 AS b),
Numbers AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS Number FROM L4)
SELECT
t.c1,
t.c2,
SUBSTRING(',' + t.c2 + ',', Number + 1, CHARINDEX(',', ',' + t.c2 + ',', 
Number + 1) - Number - 1) AS Item,
ROW_NUMBER() OVER(PARTITION BY t.c1 ORDER BY n.Number) AS rn
FROM
#t AS t, Numbers AS n
WHERE
n.Number <= LEN(t.c2)
AND SUBSTRING(',' + t.c2 + ',', n.Number, 1) = ','
ORDER BY
t.c1, rn
GO
DROP TABLE #t
GO
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • Retrive data from two tables into one internal table.

    Hi SDN,
    I am downloading the Assets data from two tables ANLA,ANLZ.
    there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
    can you please send me the SELECT Syntax for this probl.....
    Thank you & Regards,
    Manoj

    Hi manoj,
    Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
    data: begin of itab occurs 0,
            BUKRS like anla-BUKRS,
            ANLN1 like anla-ANLN1,
           BDATU like anlz-BDATU,
            end of itab.
    select anlabukrs anlaANLN1 anlzBDATU  into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
    Please come back for any clarification.
    Thanks and Regards,
    saurabh

  • How to fetch data from different sources into one source (like into Ztable)

    hi friends,
    As per our client requirements they want to develope an Inventory and an Ontime delivery report in BO on top of Oracle database.
    Situation is some thing like they have ECC 6.0.and they want to collect all inventory and ontime delivery data at one place.According to me that could be one Ztable in which we can gather all data.Apart from that they are going to use Data Integrator in which they can directly fetch the data from R/3 system(They dont want to have BI system) and put all data in Oracle DB.On top of ORacle BO person can develop BO reports.
    My question is how to fetch all data at one place and what are the tables going to be use.
    kindly help me out as its very important project.
    Thanks
    Abhishek

    The following is my standard reply to those who need to get old data from a backup in one account and add it to another account.  The method described here may be applied to your case.  It would be a bit of a long process, though.
    When connected to the account you want to GET data from, Go to Settings>iCloud and turn all data that is syncing with iCloud (contacts, calendars, etc.) to Off. 
    When prompted choose to keep the data on the iPhone. 
    After everything is turned off, scroll to the bottom and tap Delete Account.  Next, set up a new iCloud account using a different Apple ID and turn iCloud data syncing for contacts, etc. back to On.  When prompted, choose Merge.  This will upload the data to this new account.
    Note that this only affects the "Apple data" like contacts, calendars, reminders, etc.  Many third party apps also use iCloud to store data files there.  These files may be lost in the process, unless the apps also keep the data locally on the device.
    NOTE:  Photos in the photo stream (if you use it) will not transfer to the new account.  It is advised that you save the photos to a computer before performing the account switch. 

  • How do I merge my Mail data from two Macs into one?

    One is Lion and the other is Mountain Lion, both 27" iMacs. I have saved the Mail data from the Lion one and will reformat its HDD for a clean install of Mountain Lion.  Then I plan to import a (CCC) clone of my newer iMac.  I need to merge the mail because some mail items are missing on the clone that existed on the erased iMac.

    Copy or move the song files from one account to a shared location and then drag them into the open iTunes window when logged into the other account.
    (60844)

  • How Can I Combine Podcasts from Two Computers Into One ?

    I download podcasts on two computers - my home PC and my work/travel laptop. My IPod syncs to my home PC. What I would like to be able to do is transfer all the podcasts I have downloaded from my laptop to my home PC (as my internet speed at home isn't great), then sync it all to my IPod. Is this possible ?

    Well it works.....sometimes. It works OK with audio podcasts, but not with *.mov video podcasts. It DOES work with *.M4V video podcasts. I found this out by trying to add all the Tiki Bar TV files, and only the Boomerang episode transferred OK.
    The strange thing is this - while the *.MOV vpodcasts don't show up in the Podcast window in ITunes, they DO transfer over and show up in Library>Genre 'Podcasts'>. How can I force them to appear in the Podcasts window ?
    Cheers
    Blewyn

  • Retrieve of data from two columns into one column

    For eg: i have a data in a table with columns A & B of same size
    A B
    1 2
    2
    3 1
    4 2
    5 3
    6 5
    7 1
    8 4
    9
    10 8
    Through a select i want the output of my data in one single
    columns, Well I can do this by using union.
    But my output should be like
    if I select by condition where A=2
    my output should be
    2
    1
    3
    7
    4
    because all these numbers are linked with 2 how do i do this
    because it is like searching the number 2 in two columns and wherever this number 2 is linked i should get all the data relevant to it.
    Hope u got my point what i exactly want
    Can anyone help me it is quite urgent.
    Regards
    Vamsi Mohan

    i do not a concatenated data
    i have a data in a table with columns A & B of same size
    A B
    1 2
    2
    3 1
    4 2
    5 3
    6 5
    7 1
    8 4
    9
    10 8
    if my where condition is 'where A=2'
    my output should be
    1
    2
    3
    4
    5
    6
    8
    10
    i want my query to search as loop so that it keeps on searching
    for related data as in my case it is
    2 is linked to 1
    1 is linked to 3
    3 is linked to 4
    my query should keep on seaching for linked numbers till
    it does not find any mathing linked numbers
    and the resulted output should come in one single column

  • How to combine many rows into one row

    Hi all,
    I have a question regarding to how to combine many rows into one row?
    My result set is like that:
    ITEM_NO NAME1
    11 abc
    11 cde
    11 fg
    Want to combine them into
    ITEM_NO NAME1
    11 abc;cde;fg
    would anybody can tell me how to do that? Thanks
    Ray

    You can check this --
    satyaki>
    satyaki>
    satyaki>create table t
      2  as
      3      select 11 ITEM_NO, 'abc' NAME1 from dual
      4      union all
      5      select 11 ITEM_NO, 'cde' NAME1 from dual
      6      union all
      7      select 11 ITEM_NO, 'fg' NAME1 from dual;
    Table created.
    satyaki>
    satyaki>
    satyaki>
    satyaki>set lin 10
    satyaki>
    satyaki>desc t;
    Name              Null?    Type
    ITEM_NO                    NUMBER
    NAME1                      VARCHAR2(3)
    satyaki>
    satyaki>
    satyaki>set lin 1000
    satyaki>
    satyaki>
    satyaki>
    satyaki>SELECT ITEM_NO,
      2         LTRIM(MAX(SYS_CONNECT_BY_PATH(NAME1,';'))
      3         KEEP (DENSE_RANK LAST ORDER BY curr),';') AS NAME1_DET
      4  FROM   (SELECT ITEM_NO,
      5                 NAME1,
      6                 ROW_NUMBER() OVER (PARTITION BY ITEM_NO ORDER BY NAME1) AS curr,
      7                 ROW_NUMBER() OVER (PARTITION BY ITEM_NO ORDER BY NAME1) -1 AS prev
      8          FROM   t)
      9  GROUP BY ITEM_NO
    10  CONNECT BY prev = PRIOR curr AND ITEM_NO = PRIOR ITEM_NO
    11  START WITH curr = 1;
       ITEM_NO  NAME1_DET
            11  abc;cde;fgRegards.
    Satyaki De.

  • HT1449 how do you move all music from two computers into one itunes account?

    How do you move all music from two computers into one itunes account?

    An "iTunes account" is an online account you use for buying music, like a bank account.  An iTunes collection is the media you see when you open iTunes. Which do you mean?
    If it is two computers, it would also help to know where these are located. Are they on the same local network? If they are, try Home Sharing (and you have control of both and you aren't just trying to get music fro your computer to your friend's computer in another state).  If they are not, you'll have to use an external hard drive or flash drive.
    Is this on a PC? Your computer information says Windows but you posted this in the iTunes for Mac forum.

  • OBIEE 11g - Combine data from two Oracle tables

    Good day!
    I tried to combine data from two Oracle tables as fact data, but it doesn't work.
    My steps: I created SCOTT.EMP2 table from SCOTT.EMP table, update EMPNO and ENAME values of EMP2 table to distinguish data of my tables. Then I imported physical tables DEPT, EMP and EMP2 to BIEE 11g, created joins DEPT-EMP and DEPT-EMP2 in physical diagram. Then I dragged DEPT and EMP tables to BMM, and EMP2 table to EMP as second LTS. In Content tab for EMP and EMP2 I checked "This source should be combined with other sources at this level" checkboxes. Then I renamed logical tables EMP and DEPT to Employees and Departments and dragged them to Presentation area. In Answers I created Analysis with columns DNAME and ENAME.
    The problem is that data on results tab is only from one physical table EMP or EMP2 (depending on the order of sources EMP and EMP2 of LT Employees) and not from both.
    Can anybody help? Am I missed something?
    Al.

    Hi Al,
    I think you have to define the content of the LTS.
    http://download.oracle.com/docs/cd/E12096_01/books/admintool/admintool_BusModSetup16.html
    You have to specify the content of the different fragments.
    http://download.oracle.com/docs/cd/E12096_01/books/admintool/admintool_SetUpAggNav3.html#wp1005333
    Maybe you have to add an additional column 'Source' ('EMP1', 'EMP2')
    Good Luck,
    Daan Bakboord
    http://obibb.wordpress.com

  • How to extract data from info cube into an internal table using ABAP code

    HI
    Can Anyone plz suggest me
    How to extract data from info cube into an internal table using ABAP code like BAPI's or function modules.
    Thankx in advance
    regds
    AJAY

    HI Dinesh,
    Thankq for ur reply
    but i ahve already tried to use the function module.
    When I try to Use the function module RSDRI_INFOPOV_READ
    I get an information message "ERROR GENERATION TEST FRAME".
    can U plz tell me what could be the problem
    Bye
    AJAY

  • How to combine a few PDF files into one with Adobe reader?

    how to combine a few PDF files into one with Adobe reader?

    Hi aho,
    You would need either Acrobat (link to free 30 day trial) or our PDF Pack subscription service to perform that task.
    What can I do with Reader?
    Let me know if you have further questions!
    Regards, Stacy

  • Merging rows into one row but into SEPARATE Columns

    Hello Gurus,
    I have searched alot on OTN and many other places, but no where I could get the solution of how can we merge rows into one row but separate column. For example
    Consider the below scenario
    "DEPARTMENT", "EMP","NAME","SUBJECT"
    "Electronics","1","Sam","LIC"
    "Electronics","2","Pam","VLSI"
    "Electronics","3","Tom","C"
    "Mech","1","Abu","Thermo"
    "Mech","4","Lina","Machines"Now, I need the output like
    Based on Department as Group By Clause
    "DEPARTMENT", "EMP1","NAME1","SUBJECT1","EMP2","NAME2","SUBJECT2","EMP3","NAME3","SUBJECT3"
    "Electronics","1","Sam","LIC","2","Pam","VLSI","3","Tom","C"
    "Mech","1","Abu","Thermo","4","Lina","Machines"
    The row data to be loaded into separate columns. Name of the column is not an issue... can be anythingIn all the forums which I went through I could find them loading into a single column, but not into respective separate columns.
    Any help would be much appreciated.
    Thanks

    848265 wrote:
    Frank,
    I saw your name nearly n number of times, as I went through many forums today... And the link which you have just posted, I went through it today afternoon.
    Could you please explain this bit taken from your dynamic pivot post.
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;Many Thanks.You only need that when you need column aliases based on the actual data (and you explicitly said you don't need that) or when can't put an upper bound on the number of columns to be displayed. If that doesn't apply to this problem, then don't use any kind of dynamic SQL (like the code above); it makes the job much more difficult, less efficient and less robust.
    Here's what the code above is doing.
    If you were hard-coding a query that showed the number of people in each job, and you knew that the possible jobs were 'ANALYST', 'CLERK' and 'MANAGER', then you might hard-code a query like this:
    SELECT    deptno
    ,       COUNT (CASE WHEN job = 'ANALYST'  THEN 1 END)     AS analyst
    ,       COUNT (CASE WHEN job = 'CLERK'    THEN 1 END)     AS clerk
    ,       COUNT (CASE WHEN job = 'MANAGER'  THEN 1 END)     AS manager
    FROM       scott.emp
    GROUP BY  deptno
    ;If the jobs had different names, or if there were not 3 different jobs, then you would have to change the lines in the SELECT clause that start with ", COUNT ( CASE ...".
    The code you posted is from an example of dynamic SQL, where you first run a Preliminary Query . (What you posted above is, in fact, the complete preliminary query.) The output of that preliminary query is exactly the variable part of the real query, such as:
    ,       COUNT (CASE WHEN job = 'ANALYST'  THEN 1 END)     AS analyst
    ,       COUNT (CASE WHEN job = 'CLERK'    THEN 1 END)     AS clerk
    ,       COUNT (CASE WHEN job = 'MANAGER'  THEN 1 END)     AS managerYou then use this output as part of your main query. In other words, you can write something today that will generate exacrly as many columns as you need next year, with names from the data as it is next year. How? because you're not writing the full query today. The variable part will be written by the preliminary query when it runs next year.

  • A way to roll up rows into one row

    Is there a way to "roll up" a set number of rows into one row? I would like to have a row that can be expanded into several rows by clicking a plus sign or something similar. Anyway to do this?
    Regards,
    Mark

    Mark,
    Sorry, it didn't occur to me that you meant "hiding". It sounds like you already know how to hide and unhide but unfortunately there are no shortcuts. I agree that it would be nice to have a way to unhide a selected row or column and if my memory serves me I submitted a request for this feature some months ago. May I suggest that you also go to Main Menu > Numbers > Provide Numbers Feedback.
    The more requests for features they receive the better the chance for getting them in future updates. Best wishes,
    pw

  • How to upload the data from two sheets in one excel into SAP

    Hi experts,
                    My requirement is to upload the data from two sheets in an excel into an internal table.How can this be achieved.Is some OLE application has to be used?
    Thanks
    Abhishek

    Hi
    see this program will upload excel file to application.
    *& Report  ZSD_EXCEL2
    REPORT  ZSD_EXCEL2.
    types: begin of ttab ,
          fld1(30) type c,
          fld2(30) type c,
          fld3(30) type c,
          fld4(30) type c,
          fld5(30) type c,
          end of ttab.
    data: itab type table of ttab with header line.
    selection-screen skip 1.
    parameters: p_file type localfile default
                'C:\test.xls'.
    selection-screen skip 1.
    at selection-screen on value-request for p_file.
      call function 'KD_GET_FILENAME_ON_F4'
           exporting
                static    = 'X'
           changing
                file_name = p_file.
    start-of-selection.
      clear itab. refresh itab.
      perform upload_data.
      loop at itab.
        write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.
      endloop.
    * Upload_Data
    form upload_data.
      data: file type  rlgrap-filename.
      data: xcel type table of alsmex_tabline with header line.
      file = p_file.
      call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           exporting
                filename                = file
                i_begin_col             = '1'
                i_begin_row             = '1'
                i_end_col               = '200'
                i_end_row               = '5000'
           tables
                intern                  = xcel
           exceptions
                inconsistent_parameters = 1
                upload_ole              = 2
                others                  = 3.
      loop at xcel.
        case xcel-col.
          when '0001'.
            itab-fld1 = xcel-value.
          when '0002'.
            itab-fld2 = xcel-value.
          when '0003'.
            itab-fld3 = xcel-value.
          when '0004'.
            itab-fld4 = xcel-value.
          when '0005'.
            itab-fld5 = xcel-value.
        endcase.
        at end of row.
          append itab.
          clear itab.
        endat.
      endloop.
    endform.

  • Combine the data of two DSOs into one

    Hello experts,
    how to load the data of two DSOs into a single one using transformations and DTPs?
    Example:
    DSO A keyfields: X,Y,Z / attributes M,N,O
    DSO B keyfields: X,Y,Z / attributes P,Q
    DSO C keyfields: X,Y,Z / attributes M,N,O,P,Q  (result should be a single data record!)
    In the transformation between DSO A and C I map all keyfields and attributes M,N,O (no mapping for P and Q, meaning no transformation rule). For B to C mapping is all keyfields and attributes P, Q (no mapping for M,N,O, no transformation rule).
    When I now load the data of DSO A and DSO B to DSO C I either see the attributes M,N,O or P,Q. This means that only the latest DTP is available and overwrites the attributes with blank values of the first DTP.
    I have a solution using ABAP coding but according to the SAP Training courses (BW330) it should work without using ABAP coding.
    Any help is highly appreciated.
    Thanks in advance.
    Marco

    Hi Marco,
    Thanks again
    I looked into BW330 Business information warehouse - Modelling.
    Course version : 2006 Q2
    Material number : 50079531
    I looked into the page 281 still no luck.
    just an overview i need to create X,Y,Z,M,N,O as info objects characteristics
    and P, O  as infoobjects keyfigure.
    None of them will have attributes and i load XYZMNO to DSO1 and same XYZPO to DSO2.
    Then map DSO1 - DSO3 and  DSO2 - DSO3 and carry out the steps to get the data from DSO1 and DSO2 to DSO3.
    Am i right.
    Regards,
    Harish

Maybe you are looking for

  • Storage type to be assigned to particular storage location

    Hi, As per clients new business requirement, 2 storage locations of a plant are assigned to same warehouse. But as the storage types comes under warehouse they come under both the storage locations. Is there any configuration to assign specific stora

  • I just did two System Restores (and clicked something that asked me about "[something -exe]," and now Firefox won't open at all.

    I hope someone can help. My husband did something to update Firefox (or Firefox just automatically updated today, I don't know which), but I didn't like the new toolbar much, so I did a System Restore to get back the old one. That didn't work, so I t

  • Ipod connection to pc

    I have an older version of the Ipod Scroll. It does not have a dock port only a firewire port. There must be some way that I can connect it to my PC, just no one I have spoke to can help me. Is there an adapter from firewirt to usb, and if so where c

  • Ram still being used after quitting

    hi, I know Mavericks handles Ram in a more effective way but why is it that I have programmes still running in the activity Monitor even though I have quit them?

  • Valid serial number

    I just bougtht Adobe Photoshop CS5 extended.  A friend of mine looked at it and declared it be a counterfeit copy.  The packaging and everything appears to be genuine.  I have installed it and was able to register it with Adobe and get updates.  Havi