Taking data from one column and spread it out into multiple columns

I have a table that I wish to take the multiple values out of one column and stick each into its own column..
The data looks like this:
subscriber id benefit plan
12345 Med
12345 Drg
98765 Med
98765 Drg
I want it to look like:
subscriber_id pc_med
12345
select distinct subscriber_id,
(select grp07_benefit_plan from martin_7265_anoc
where grp07_benefit_plan_type = 'MEDICAL ') pc_med,
(select grp07_benefit_plan from martin_7265_anoc
where grp07_benefit_plan_type = 'DRUG ') pc_drg
from martin_7265_anoc

user12296489 wrote:
I have a table that I wish to take the multiple values out of one column and stick each into its own column..Multiple values in a single column is a violation of relational design. Makes it very difficult to implement data integrity. And there is the inevitable complexity and performance knock when trying to extract distinct values from the single column.
Thus your attempt at fixing it is hopefully a permanent solution and not a a hack trying to make a broken db design to work?
As Daniel said, it is very hard to make any sense of the example you have posted. But this is not the first time here that a poster wants to extract multiple values from a string column - so the basic principles of how to do it, remains the same.
You need to have a means to identify each distinct value. This is usually done by identifying the separator character used between values. Such as a space or a comma.
If the values are fixed length, then you can use sub-strings with explicit positions and lengths to extract the values from the string.
The typical case is the former, which means you need to tokenise (split) the string. There are a number of ways to do this. I posted an example in {message:id=1807978} that shows how to do it via a PL/SQL function. There are numerous other ways, such as using SQL only. If you search for a keywords like "+splitting string+", it should turn up these examples.

Similar Messages

  • How can I Move data from one column to another in my access table?

    I have two columns, one that stores current month’s data and one that stores last month’s data. Every month data from column 2 (this month’s data) needs to be moved to column 1 that holds last month’s data. I then null out column 2 so I can accumulates this month’s data.
    I understand how to drop a column or add a column, how do I transfer data from one column to another.
    Here is my trial code:
    <cfquery name="qQueryChangeColumnName" datasource="#dsn#">
      ALTER TABLE leaderboard
      UPDATE leaderboard SET  points2 = points3
    </cfquery>
    Unfortunately, I get the following error:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in ALTER TABLE statement.
    How can I transfer my data with the alter table method?

    I looked up the Access SQL reference (which is probably a
    good place to start when having issues with Access SQL), and
    it suggests you probably need a WHERE clause in there.
    I agree the documentation is a good place to start. But you should not need a WHERE clause here.
    Too few parameters. Expected 1.
    If you run the SQL directly in Access, what are the results? At the very least, it should provide a more informative error message..

  • Report to display (actuals data from one cube and plan from another)

    Hi Gurus,
             I have a requirement in reporting to display actual data from one cube and plan data from a different one.
            The example below might give a clear picture of the requirement.
    rows has key figures and columns = months
    Jan |  Feb |  Mar |  Apr |  May |  Jun  ...   ....
    GrossSales
    Net Sales   
    Now if I run the report for Current month (Apr), then for the months of (Jan, Feb and Mar) i need to get the data from CUBE1   and for the remaining months (Apr thru Dec) from CUBE2.
    Similarly when i run the report next month(may), 
    then (data for Jan, Feb, Mar, Apr  from CUBE1)
    and ( May thru Dec from CUBE2)
    Any suggestions.
    Thanks in Advance
    Kumar

    Hi Henry,
         We alreadey have a multi provider which includes
    FinDat Cube(CUBE1) for actuals and Comm.Goals cube (CUBE2) for plan.
    So you suggest that we have two versions of key figure for actual and plan.
    ie. each KF will have two versions.
    actuals = (version 10, FiscPer<curr.mnth, key figure, acutals cube)
    Plan = (version 20, FiscPer>=curr.mnth, key figure, comm.goals cube)
    eg:
    Jan | Feb | Mar | Apr | May | Jun ...
    GrossSales(Act)
    GrossSlaes(Plan)
    Net Sales(Acutal)
    Net Sales(Plan)
    Correct me if I am wrong.
    the report has a lot of key figures, having two versions for each kf will be confusing.
    the user would like to see
    Jan.....| ...Feb  |..Mar |..Apr.....|  May  | 
    GrossSales   Act Value|Act.V |Act.V| PlanVal|PlanVal|
    Net Sales
    where Act.Value is from CUBE1
             Plan Value is from CUBE2
    Thanks
    Kumar

  • I would like to repatriate data from iCloud Contacts and iCloud Calendar back into my regular Outlook Contacts and Calendar and delete iCloud from Outlook. How?

    I would like to repatriate data from iCloud Contacts and iCloud Calendar back into my regular Outlook Contacts and Calendar and delete iCloud from Outlook. How?

    Me too, I want to be able to synch other devices with my laptop but on trying it has deleted all contacts on my blackberry and will not synch either calendar or contacts.

  • How to copy data from one column to other column

    hi,
    can any one tell me how to copy data of  one column to other column for some specific data
    example
    productno  ocalyear        actualsales  prevplansales   currentplansales
    p001       2007                  100              120                   
    p002       2007                   90               100
    p003       2007                  120              130
    p004       2007                  140              120
    p005       2007                  150              150
    i want to copy data of p001 and p002 from prevplansales to current plansales
    productno  ocalyear        actualsales  prevplansales   currentplansales
    p001       2007                  100              120              120     
    p002       2007                   90               100              100
    p003       2007                  120              130
    p004       2007                  140              120
    p005       2007                  150              150
    is it possible to do?
    please suggest me.
    i will assign points

    Hi,
    I think the needed techniques are already described in the documentation, e.g. in
    http://help.sap.com/saphelp_nw70/helpdata/en/45/e641e4c61256dee10000000a114a6b/frameset.htm
    or
    http://help.sap.com/saphelp_nw70/helpdata/en/45/e641e4c61256dee10000000a114a6b/frameset.htm
    The main techiques used in the above example to bind the filter of the planning function to selected (marked) objects in the analysis item or to drop down boxes (or both). These techniques are used in the above examples.
    Regards,
    Gregor

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Help with lists and Numbers - how can I separate data from one column?

    I have a series of data entries that have two or three pieces of information listed in one column (it was a list copied from the Internet). My data is in this form all in one column (ie Column A):
    XXXX -- YYYY, ZZZZ
    I want to be able to easily split that data into three columns (A, B, and C) without having to go through and manually separate all of the entries? I'd ideally like to have XXXX in one column, the '--' removed, YYYY in another column, and ZZZZ in a third column, like this:
    Column A Column B Column C
    ====== ====== ======
    XXXX YYYY ZZZZ
    Is this possible? Any help is appreciated.

    BlooGoo
    Open or paste your material in your favorite texteditor. TextEdit will suffice but there are better applications. Make sure your material is consistent, especially that there are no stray characters or extra spaces studded in the text. You can do this by using the clean up routine as described below.
    1. Copy the set of characters you want to replace. In this case " -- " Note that there are spaces on each side of the dashes and you want to get rid of those.
    2. Open the *Find and Replace* dialogue:
    +Menu > Edit > Find > Find…+ (or command f)
    Paste the " -- " into the Find: field, then type a comma in the Replace: field or
    Copy and paste a tab from the document or
    Click on the Advanced button and enter a tab using the Insert… button that appears.
    3. Click *Replace All.*
    Repeat as necessary. If it doesn't seem to work, copy and paste the bits that stick, usually there is something not visibly different but different as far as the computer iust concerned.
    When you are finished save the results as a comma or tab delimited delimited .txt file and reopen it in Numbers.
    Peter

  • Copy the data from one column to another column using @

    I have two columns here - A and B.
    Column A has a complicated formula that will generate results. I wanted the results in Column A to be reflected in Column B without pasting the A's formula in B. This will save me the trouble of editing formulas in more than 1 column if there is a need.
    I saw somewhere that you can use "@" in column B but I have no idea how to use it.
    Assumingly column A is the first column. I tried to insert '@1' in B's formula and change B's column properties' Data Format as "Treat Text as HTML". It does not work.
    Please advise how I can do that.

    So is there any way to copy the data in Column A into Column B without putting the same formula? something like in Excel where we put "=C1". Its not possible in BI as it comes in excel.....The only way is to create a duplicate column in RPD or Answers screen and incorporate the formula and giving different name to it.
    whats the problem if you duplicate the column with same formula?....Ok still if you dont want to see identical just write some pseudo logic say
    Duplicated column f(x) case when 1=0 then column_name else formula end.....so it appears different to see but it outputs same.
    UPDATED POST
    Dont create in RPD,you can create a dummy column in that report request and change the f(x) to the above case i mentioned by taking the column from columns button in edit formula screen so when ever you edit the actual column formula that would reflect in the dummy column also as it is replicating from original one.Try and see
    hope helps you.
    Cheers,
    KK
    Edited by: Kranthi.K on Jun 2, 2011 1:26 AM

  • Fetch data from one table and insert into two tables in desired format

    I have similar to the following data in a table and it is not normalized. The groupID is being used to group two records of similar nature.
    DECLARE @OldDoc TABLE (oldDocID INT, groupID INT, deptID INT)
    INSERT INTO @OldDoc (oldDocID, groupID) VALUES (1, NULL, 111),(2,NULL,111),(3,1,111),(4,NULL,333),(5,1,222),(6,NULL,333),(7,2,222),(8,2,333),(9,NULL,111),(10,3,222),(11,NULL,333),(12,3,444)
    I need to process the data from the above table (@OldDoc) and write into two new tables (@NewDoc and @NewDocGroup) as follows.
    oldDocID should be stored as newDocID when inserting to @NewDoc table. Only records with groupID NULL and one record (first one) per group should be considered (For example, oldDocID 5 is not considered as 3 and 5 belong to the same groupID 1) for insertion. 
    DECLARE @NewDoc TABLE (newDocID INT)
    INSERT INTO @NewDoc (newDocID) VALUES (1),(2),(3),(4),(6),(7),(9),(10),(11)
    All records from @OldDoc should be considered for insertion into @NewDocGroup table. OldDocID is inserted as NewDocID and deptID is as-is. Instead of groupID, the ID of the first record in the 
    group should be considered as parentNewDocID (For example, 3 is considered as parentNewDocID for newDocID 5 as 3 and 5 belong to the same groupID in @OldDoc table) for the newDocID.
    DECLARE @NewDocGroup (newDocID INT, parentNewDocID INT, deptID INT)
    INSERT INTO @NewDocGroup (newDocID, parentNewDocID, deptID) VALUES (1,1,111),(2,2,111),(3,3,111),(4,4,333),(5,3,222),(6,6,333),(7,7,222),(8,7,333),(9,9,111),(10,10,222),(11,11,333),(12,10,444)
    How do I accomplish the above using SQL ? Thanks for the help.

    >> I have similar to the following data in a table and it is not normalized. The group_id is being used to group two records [sic] of similar nature. <<
    Rows are not records. Tables have to have a key by definition. You do not do math with identifiers, so they should not be numeric. Let's ignore that error for now. In short, you are posting garbage. If you had followed Forum Netiquette, would you have posted
    this? 
    CREATE TABLE Old_Documents
    (old_doc_id INTEGER NOT NULL PRIMARY KEY, 
     group_id INTEGER, 
     dept_nbr INTEGER NOT NULL
       REFERENCES Departments (dept_nbr));
    INSERT INTO Old_Documents(old_doc_id, group_id, dept_nbr) 
    VALUES  (1, NULL, 111), 
    (2, NULL, 111), 
    (3, 1, 111), 
    (4, NULL, 333), 
    (5, 1, 222), 
    (6, NULL, 333), 
    (7, 2, 222), 
    (8, 2, 333), 
    (9, NULL, 111), 
    (10, 3, 222), 
    (11, NULL, 333), 
    (12, 3, 444);
    >> I need to process the data from the above table (Old_Documents) and write into two new tables (New_Documents and New_Documents_Groups) as follows. <<
    Just like punch cards and mag tape data processing! Being old and being new are a status, not another kind of entity. But that is how mag tapes work. And you even use the verb "fetch" from tape files. This design flaw is called  attribute splitting.
    Do you have a Male_Personnel and Female_Personnel table? NO! It is just Personnel! 
    >> old_doc_id should be stored as new_doc_id when inserting to New_Documents table. Only records [sic] with group_id NULL and one record [sic] (first [sic; no ordering in a table] one) per group should be considered (For example, old_doc_id 5 is not considered
    as 3 and 5 belong to the same group_id =1) for insertion. <<
    Think about your punch card mindset. Why did you physically materialize that redundant New_Documents table? Let me answer that: this is how you work with punch cards! In SQL we use a VIEW:
    CREATE VIEW New_Documents (new_doc_id)
    AS 
    SELECT old_doc_id 
      FROM Old_Documents;
    >> All records [sic] from Old_Documents should be considered for insertion into New_Documents_Groups table. The old_doc_id is inserted as new_doc_id and dept_nbr is as-is. Instead of group_id, the ID [sic: which identifier??] of the first [sic: tables
    have no ordering like a deck of punch cards] record [sic] in the group should be considered as parent_new_doc_id (For example, 3 is considered as parent_new_doc_id for new_doc_id 5 as 3 and 5 belong to the same group_id in Old_Documents table) for the new_doc_id.
    <<
    Why not use 5 as the parent? My guess is that you are trying to form equivalence classes. See:
    https://www.simple-talk.com/content/print.aspx?article=2020
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Taking data from one program to fill in pdf form

    I'm pretty new to this and I am not even sure this would be possible. I've created a fillable .pdf form and I was wondering if there is a way to transfer information from one software program into it's correct fields on the fillable form. For example, the person's contact information is seen on the screen from on program, but not in any structure to just copy and paste, and I would like to somehow very quickly autopopulate/transfer it to the form?

    There's no way to do that with JS. What you can do is export the data to a
    plain-text file and then use JS to import that file and populate the
    fields. If you're not using Acrobat X it would also be possible to do it in
    a smoother way using a local DB, but that is also much more complex to
    implement.
    For a more automated solution you will need to use a plugin or stand-alone
    application. You can ask at the Acrobat SDK forum about those.

  • Creating addititional records from one record and spreading total accross

    Can anyone help me with the following script logic scenario...
    We have an account with $$ and wish to spread it accross the remaing months of another scenario. 
    For example, In 2012.Jan, we have an Actual amount = 10,000.  Also, 2012.Jan Forecast = 5,000. 
    I need to take the difference -5,000 and push it into Forecast 2012.Feb, 2012.Mar, ... 2012.Dec and spread it evenly (-454.55).

    Hi Danny,
    Welcome to the forums!
    Here is a sample script to get you going:
    //Scope in the ACTUAL and FORECAST categories
    *XDIM_MEMBERSET CATEGORY=ACTUAL,FORECAST
    //Only scan through the actual data and only use the forecast data in the GET command within the *REC statement down below
    *XDIM_NOSCAN CATEGORY=FORECAST
    //Scope in the time period 2012.DEC
    //You should eventually make this dynamic using a *SELECT statement
    *XDIM_MEMBERSET TIME=2012.JAN
    *WHEN *
    *IS *
    //This for loop should become dynamic using a *SELECT statement. Choosing the months to forecast
    *FOR %MYTIME% = 2012.FEB,2012.MAR,2012.APR,2012.MAY,2012.JUN,2012.JUL,2012.AUG,2012.SEP,2012.OCT,2012.NOV,2012.DEC
    //Note you will need to add a property to your CATEGORY dimension called FCST_NUM and put a value of 11 for the ACTUAL member. This value will need to be updated as the number of months to forecast changes.
    *REC(EXPRESSION=((%VALUE%-GET(CATEGORY="FORECAST"))/FLD(CATEGORY.FCST_NUM),CATEGORY=FORECAST, TIME=%MYTIME%)
    *NEXT
    *ENDWHEN
    *COMMIT
    Two caveats is that data must always reside in the ACTUAL category. Since the logic is looping through every record in the ACTUAL category. Also, all the other data must be at the same intersection or else the GET statement will be looking in the wrong place. i.e. DataSrc for the Actuals and Forecast has to be at the INPUT member or else you would need specify where the data is for forecast category in the GET statement.
    Let me know how this goes.
    Thanks,
    John

  • How to read LONG RAW data from one  table and insert into another table

    Hello EVERYBODY
    I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
    when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
    i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
    and then sound will be played from the temp table.
    declare
         tmp sound.music%type;
         temp1 sound.music%type;
         item_id ITEM;
    cursor c1
    is select music
    from sound
    where lang=:LIST10;
    begin
         open c1;
         loop
              fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
              temp1:=temp1||tmp;
              exit when c1%notfound;
         end loop;
    CLOSE C1;
    insert into temp values(temp1);
    item_id:=Find_Item('Music');
    go_item('music');
    play_sound(item_id);
    end;
    but when i'm clicking the button it generates the following error.
    WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
    ORA-06502: PL/SQL: numeric or value error
    SQL> desc sound;
    Name Null? Type
    SL_NO NUMBER(2)
    MUSIC LONG RAW
    LANG CHAR(10)
    IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
    THANKS IN ADVANCE.
    D. Prasad

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Taking invoice from one address and paying to other address

    Hi Gurus
    Please guide me on this.  This question is extension to the other question i asked a minute ago.
    I have a vendor with a payment recipient partner(different address) on it. 
    Ex: Invoice comes from the main vendor 11111 and check should go to the recipient 22222.
    Scenario 1: how do i enter the invoice via FB60? Should I enter the invoice for vendor 11111 because he sent it? if yes, the open item will go to 11111. And i cannot pay 22222 because there is no open item there.
    Scenario 2: How would it be if 11111 gets a PO and sends back an invoice. I am asking about the MIGO MIRO situation.
    Please help me.. Points guaranteed.
    Thank you
    Manu

    Hi Manu,
    In your example here the accounting data and the PO should be set up at "22222" level.
    The Vendor that is sending you the invoice could be seen as a "Head office" partner function or something similar but from a legal point of view you need to make sure you have the correct bank details set up in "22222" to pay them.
    I dont believe you need to record from a Finance point of view that "11111" sent you the invoice.

  • Can you copy data from one spreadsheet and add it to existing data in another spreadsheet?

    I have data that is being downloaded from googledocs into a numbers spreadsheet.  It happens weekly but it creates a new spreadsheet each time it downloads.  I need to copy 50 cells and add the quantities to an existing spreadsheet without it replacing the originals.  Is there a formula or way that makes this happen? 

    Generally if you add a new row at the end of your table you can highlight the cell where you want the paste to start and then paste the data.  I do not have Numbers on an iOS device so you may get more reliable help i the iOS forum-- which is here: https://discussions.apple.com/community/app_store/iwork_for_ios

  • Need to split data from one row into a new row redux

    Hi folks,
    I asked this question about eight months ago (see thread https://discussions.apple.com/message/23961353#23961353) and got an excellent response from forum regular Wayne Contello.  However, I need to perform this operation again and when I attempted it recently, I am now greeted with a yellow warning triangle.  Clicking it shows "This formula can’t reference its own cell, or depend on another formula that references this cell."
    What I'm trying to do is the following:
    I have an excel file that keeps track of members of a social group.  The file places each member "unit" on a single row.  The unit can be a single person or a couple.  Columns are labeled "First1" "Last1" "Hometown1" "B-day1" while the second member of the unit is identified in columns like "First2" "Last2" etc.
    What I'd like to do is duplicate those rows with two people (which I'll do by hand) but have a way of deleting the "xxxx2" data from one row and the "xxxx1" data from the duplicate row.
    Wayne's illustrated solution was to create a blank sheet and enter the following formula in cell A2:
    =OFFSET(Input Data::$A$2, INT((ROW()−2)÷2), COLUMN()−1+IF(MOD(ROW()−2, 2)=0, 0, 4)), which apparently worked fine for me last year but now is sending up an error flag.  When I look at the formula, there is no clue except that which I quoted above.
    Can anyone (or hopefully Wayne) take a second look at this and help me out?  I can't imagine that it's a problem with using the newer version of Numbers, but who knows?  I'm using version 3.2 (1861), which is the "new" Numbers.
    Any help would really be appreciated.
    Thanks!
    -Tod

    Hi Tod,
    The error message "This formula can’t reference its own cell, or depend on another formula that references this cell." may be because your table may be different from the one you were using for Wayne's solution. Numbers has Header Rows, Footer Rows and Header Columns. Such Headers in tables exclude themselves from formulas. Excel does not recognise them as headers. What table are you using now?
    A screen shot of (the top left portion of) your table or a description of what you see under Menu > Table will help.
    Regards,
    Ian.

Maybe you are looking for

  • Acrobat 9 is Broken!

    Hi, Can anyone tell my why when opening more than one PDF Acrobat 9 Pro or Extended always crashes? The Error message is "Adobe Acrobat 9.0 has encountered a problem and needs to close. We are sorry for the inconvenience." This happens on 32 bit XP m

  • Gap_y setting ignored, conky placed incorrectly

    I have a weird problem with my Conky in Openbox. It seems to be drawn in the correct place initially, but then it snaps to the top of the screen, dragging bits of the wallpaper with it. Here is my .conkyrc: # Use Xft? use_xft yes xftfont Bitstream Ve

  • Drag and drop error in new acrobat pro 11

    I would be able to drag pages from a PDF opened in Internet explorer and drop the pages I wanted to a PDF opened in acrobat pro. In version 10 this worked but now in 11 it does not. How do i get this function to work again?

  • Create new article:  BAPI_MATERIAL_MAINTAINDATA_RT

    Hi all, When i try to create a new article by using BAPI_MATERIAL_MAINTAINDATA_RT i am getting the follow success message M3801 ("Material & changed") but article is not created. After sending the BAPI_MATERIAL_MAINTAINDATA_RT and returning without a

  • Word- pdf contains only images, no text

    Hi, i have created a Word 2010 Document with the typefaces Caslon and Kozuka. When creating the pdf with any setting (Standard, high quality, pdf/x) in Acrobat X (10.1.16) there is no text. Both "Acrobat-Create pdf-choose word file" and "Word-Acrobat