Collecting data from multiple rows into one column

I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
"CORE     10.2.0.5.0     Production"
TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
     CREATE TABLE "SKIP"."INGREDIENTS"
   (     "INGRED_ID" NUMBER,
     "INGRED_NAME" VARCHAR2(20 BYTE),
     "STORES" VARCHAR2(20 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGREDIENTS
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
  CREATE TABLE "SKIP"."PRETZELS"
   (     "PRETZEL_ID" NUMBER,
     "PRETZEL_NAME" VARCHAR2(20 BYTE),
     "PRETZEL_DESC" VARCHAR2(100 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
REM INSERTING into SKIP.PRETZELS
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
  CREATE TABLE "SKIP"."INGRED_XREF"
   (     "PRETZEL_ID" NUMBER,
     "INGRED_ID" NUMBER
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGRED_XREF
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
--  Constraints for Table INGRED_XREF
  ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
  ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
{code}
Desired output (note how the ingredients are all listed in one column, separated by commas):
{code}
PRETZEL_ID PRETZEL_NAME     PRETZEL_DESC                        INGREDIENTS
1          CLASSIC          Classic knot pretzel                SEA SALT, TABLE SALT, YEAST
2          THICK STICK      Straight pretzel, abt 1/2" in dia   TABLE_SALT, FLOUR, BEER

See the FAQ : {message:id=9360005}
Especially links concerning string aggregation.

Similar Messages

  • 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

  • Multiple Rows Into One Column Field

    Hi All,
           Today I tried one query:
    select wm_concat(ename) from emp
    group by deptno;
    I have a data that looks like this.
    CLARK,KING,MILLER,SREE
    JONES,FORD,ADAMS,SCOTT
    ALLEN,MARTIN,BLAKE,TURNER,JAMES,WARD
    Can someone help me to build an SQL command that would have the output as follows:
    I need per column 3 values....
    CLARK,KING,MILLER,
    SREE,JONES,FORD,
    ADAMS,SCOTT,ALLEN,
    MARTIN,BLAKE,TURNER,
    JAMES,WARD

    StewAshton wrote:
    That's funny, I don't get the same answer
    Why do you think you should?
    Besides, you're not the only one.
    ENAMES
    KING,BLAKE,CLARK
    JONES,SCOTT,FORD
    SMITH,ALLEN,WARD
    MARTIN,TURNER,ADAMS
    JAMES,MILLER
    Regards
    Etbin
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE 11.2.0.3.0 Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    It's from my APEX Workspace: first select from the emp table (not touched until now)
    Message was edited by: Etbin

  • Trying to convert multiple rows into multipe columns within a single row

    I am trying to convert data from multiple rows into multiple columns. Let me see if I can paint the picture for you.
    Here is a sample of the table i am trying to read from:
    Company Name Account
    1 Sam 123
    1 Sam 234
    1 Joe 345
    1 Sue 789
    1 Sue 987
    1 Sue 573
    I am trying to put this into a View that would have the data represented as such:
    Company Name Acct1 Acct2 Acct3 Acct4
    1 Sam 123 234 <null> <null>
    1 Joe 345 <null> <null> <null>
    1 Sue 789 987 573 <null>
    Many thanks in advance for your help!

    test@XE> --
    test@XE> with t as (
      2    select 1 as company, 'Sam' as name, 123 as account from dual union all
      3    select 1, 'Sam', 234 from dual union all
      4    select 1, 'Joe', 345 from dual union all
      5    select 1, 'Sue', 789 from dual union all
      6    select 1, 'Sue', 987 from dual union all
      7    select 1, 'Sue', 573 from dual)
      8  --
      9  select company,
    10         name,
    11         max(case when rn = 1 then account else null end) as acct1,
    12         max(case when rn = 2 then account else null end) as acct2,
    13         max(case when rn = 3 then account else null end) as acct3,
    14         max(case when rn = 4 then account else null end) as acct4
    15    from (select company,
    16                 name,
    17                 account,
    18                 row_number() over (partition by company, name order by 1) as rn
    19            from t)
    20   group by company, name;
       COMPANY NAM      ACCT1      ACCT2      ACCT3      ACCT4
             1 Joe        345
             1 Sam        234        123
             1 Sue        573        789        987
    3 rows selected.
    test@XE>
    test@XE>isotope

  • How To Concatenate Column Values from Multiple Rows into a Single Column?

    How do I create a SQL query that will concatenate column values from multiple rows into a single column?
    Last First Code
    Lesand Danny 1
    Lesand Danny 2
    Lesand Danny 3
    Benedi Eric 7
    Benedi Eric 14
    Result should look like:
    Last First Codes
    Lesand Danny 1,2,3
    Benedi Eric 7,14
    Thanks,
    David Johnson

    Starting with Oracle 9i
    select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
    from
    (select last, first, code, row_number() over(partition by last, first order by code) rn
    from a)
    connect by last = prior last and first = prior first and prior rn = rn -1
    start with rn = 1
    group by last, first
    LAST       FIRST      CODES                                                                                                                                                                                                  
    Lesand         Danny          1,2,3
    Benedi         Eric           7,14Regards
    Dmytro

  • Display Data from multiple models in one table

    Hi Experts,
    Is it possible to display data from multiple models in one table smltnsly.
    I have created a table dynamically.Now I would like to display data from multiple models... If this possible,can anyone give me a lead as to how to do it..
    Regards
    SU

    Hi
    Your Model Nodes be
    Model1
    ---Output_Model1
    Attrib1
    Attrib2
    Model2
    ---Output_model2
    Attrib1
    Attrib2
    and the value node is
    ValueNode
    ---Attrib1
    ---Attrib2
    Now the coding.
    int size;
    IPrivate<ViewName>.IOutput_mode1Node  node1 = wdContext.nodeOuptut_Model1();
    IPrivate<ViewName>.IValueNodeElement elem;
    size = node1.size();
    for(int i=0; i<size; i++)
       elem = wdContext.createValueNodeElement();
       elem.setAttrib1( node1.getOutput_Model1ElementAt(i).getAttrib1() );
       elem.setAttrib2( node1.getOutput_Model1ElementAt(i).getAttrib2();
       wdContext.nodeValueNode().addElement( elem );
    similar code for Model Node 2
    Regards
    Abhimanyu L

  • How to get the data from multiple nodes to one table

    Hi All,
    How to get the data from multiple nodes to one table.examples nodes are like  A B C D E relation also maintained
    Regards,
    Indra

    HI Indra,
    From Node A, get the values of the attributes as
    lo_NodeA->GET_STATIC_ATTRIBUTES(  IMPORTING STATIC_ATTRIBUTES = ls_attributesA  ).
    Similarily get all the node values from B, C, D and E.
    Finally append all your ls records to the table.
    Hope you are clear.
    BR,
    RAM.

  • How can i import the data from multiple sources into single rpd in obiee11g

    how can i import the data from multiple sources into single rpd in obiee11g

    Hi,
    to import from multiple data sources, first configure ODBC connections for respective data sources. then you can import data from multiple data sources. When you import the data, a connection pool will create automatically.
    tnx

  • 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. 

  • Items from multiple folders into one?

    Any programs that can move thing's out of multiple folders into one?
    I'm thinking in particular iPhoto, roll folders with images inside, want to move them all out and into one folder. I would rather not go through each one and move manually as could take a while, especially if there are say hundreds of folders each with photos inside i want to move into one.
    Must be a program or something that will do it?

    I find one:
    http://www.macupdate.com/info.php/id/29405/bundle-files
    I've never tested it and it has no reviews. Proceed at your own risk.
    EDIT: Make that three!
    Also, http://gotoes.org/sales/CopyMoveFilesSingleFolderMultiple/HowTo_Move_Files_To_SingleFolder.php
    ...and
    http://www.macupdate.com/info.php/id/25597/the-big-mean-folder-machine
    -mj
    Message was edited by: macjack

  • Concatenate strings from more rows into one row.

    Hi,
    what's the name of that analytical function (or connect by) that
    would return strings from more rows as one row concatenated. i.e.:
    (I know this is possible using regular pipelined functions.)
    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    select tadah().... from ...
    result:
    ROW1: STR1 STR2 STR3Thanks.

    Hi,
    Here's a basic example of SYS_CONNECT_BY_PATH.
    The query below produces one row of output per department, containing a list of the employees in that department, in alphabetioc order.
    WITH     got_rnum     AS
         SELECT     ename
         ,     deptno
         ,     ROW_NUMBER () OVER ( PARTITION BY  deptno
                                         ORDER BY          ename
                              ) AS rnum
         FROM     scott.emp
    --     WHERE     ...          -- Any filtering goes here
    SELECT     deptno
    ,     LTRIM ( SYS_CONNECT_BY_PATH ( ename
                                  , ','     -- Delimiter, must never occur in ename
               )          AS ename_list
    FROM     got_rnum
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     rnum          = 1
    CONNECT BY     rnum          = PRIOR rnum + 1
         AND     deptno          = PRIOR deptno
    ;Output:
    .   DEPTNO ENAME_LIST
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARDThe basic CONNECT BY query would produce one row per employee, for example:
    .   DEPTNO ENAME_LIST
            10 ,CLARK
            10 ,CLARK,KING
            10 ,CLARK,KING,MILLER
            20 ,ADAMS
            20 ,ADAMS,FORD
    ...The WHERE clause: <tt>WHERE CONNECT_BY_ISLEAF = 1</tt> means that we'll only see the last row for every department.
    SYS_CONNECT_BY_PATH (which is a row function, by the way, not an analytic fucntion) puts a delimiter (',' in the example above) before every item on the list, including the first one.
    The query above uses LTRIM to remove the delimiter at the very beginning.
    WM_COMCAT (or the equivalent user-defined STRAGG, which you can copy from AskTom) is much more convenient if order is not important.

  • Combine CSV columns from multiple sources into one

    Hi, 
    I am trying to import column from one CSV file and output it into additional columns on a Get-MailboxStatistics | Export-CSV command. The issue with the script I have created is that when use an Expression to create the new column it outputs all of the items
    in the column from the import CSV into one row. See script below, I have highlighted the expressions that are not working.
    Any assistance would be appreciated. 
    [Array]$Global:NotesMailSizeMaster = (Import-Csv c:\usermigration.csv).MailSizeMaster
    [Array]$Global:NotesMailSizeRefresh = (Import-Csv c:\usermigration.csv).MailSizeRefresh
    [Array]$Global:UserAlias = (Import-Csv c:\usermigration.csv).Alias
    if (!(Get-PSSnapin |
    Where-Object { $_.name -eq "Microsoft.Exchange.Management.PowerShell.Admin" }))
    ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
    $Output = ForEach ($Alias in $UserAlias)
    { Get-MailboxStatistics $Alias | select-object DisplayName, ServerName, StorageGroupName, Database, @{ Name = "TotalItemSize"; expression = { $_.TotalItemSize.Value.ToMB() } },
    @{ Name = "NotesMailSize(PreRefresh)"; expression = { $NotesMailSizeMaster } }, @{
    Name = "NotesMailSize(PostRefresh)"; expression = { $NotesMailSizeRefresh }
    $filename = (Get-Date).ToString("yyyyMMdd")
    $Output | export-csv -Path c:\"$filename-mailboxstats.csv" -NoTypeInformation

    There's a lot wrong with this script:
    1.  You're importing the same file 3x; you should import one and reference the things you need out of it.
    2.  If the CSV has more than one row in it, your .notation you're using to access the MailSizeMaster, MailSizeRefresh, and Alias properties is used incorrectly.  If you are trying to reference each of those properties from an array of different entries,
    the proper way would be:
    $Import = @(Import-Csv C:\usermigration.csv)
    $MailSizeMaster = $Import | Select-Object MailSizeMaster
    OR
    $MailSizeMaster = $Import | Select-Object -Expand MailSizeMaster
    ...the "OR" is not PowerShell. 
    3.  I don't know if you can concatenate different objects with the select-object cmdlet like you are.  However, what you could do is create a custom object to load the values into and then output that object:
    $filename = (Get-Date).ToString("yyyyMMdd")
    foreach ($item in $Import) {
    $MS = Get-MailboxStatistics $item.Alias
    New-Object PSObject -Property @{
    'DisplayName' = $MS.DisplayName
    'ServerName' = $MS.ServerName
    'StorageGroupName' = $MS.StorageGroup
    'Database' = $MS.Database
    'NotesMailSizePre' = $item.MailSizeMaster
    'NotesMailSizePost' = $item.MailSizeRefresh
    } | Select-Object DisplayName,ServerName,StorageGroupName,Database,NotesMailSizePre,NotesMailSizePost | Export-Csv -NoTypeInformation "C:\$($filename)-mailboxstats.csv"

  • Combining multiple rows into one row

    Hi all.
    My most humble apology for this question but solutions in previous threads did not seem to help much.
    Apparently, my account has not been verified and I am currently at home with no access to the SQL code so i can't post the actual code.
    We have this (mockup) of code
    Select S.C1, AViewSS.Study, AViewSS.SlotName, IST.TakenByDate, IST.ScannedByTime, SE.TimepointCalculation
    From IST
    INNER JOIN
    AViewSS ON IST.GroupID = AViewSS.GroupID and
    IST.SlotID = AViewSS.SlotID
    INNER JOIN
    S ON AViewSS.StudyID = S.StudyID
    INNER JOIN
    SE ON IST.Line = SE.Line and IST.SubLine = SE.SubLine and
    AViewSS.ScheduleID = SE.ScheduleID
    WHERE
    (IST.GroupID = 92) and (IST.SlotID between 1791 and 1795)
    and (AViewSS.VisitID = 137)
    The query currently returns this result set
    Col 1   Col 2   Taken Date  Date 1                Date 2               Date 3             
    Scanned DateTime
    Data    Data    3/12/2015  3/12/2015 7:22                                   
                    3/12/2015 7:22
    Data    Data    3/12/2015                            3/12/2015 8:47                         
    3/12/2015 8:47
    Data    Data    3/12/2015                                                    
    3/12/2015 9:27 3/12/2015 9:27
    Data    Data    3/22/2015                            3/22/2015 7:27        
                     3/22/2015 7:27
    Data    Data    3/22/2015
    Data    Data    4/12/2015
    Data    Data    4/12/2015
    Data    Data    4/12/2015
    You’ll notice that rows 1, 2, 3 are related as are rows 4, 5 and rows 6, 7, 8.
    This is what we ultimately want to see given the results above.
    In the report, rows 1, 2, 3 from the results should roll into one row with the ScannedByTimeStamp from each row returned by the query populating the appropriate report time column based on the value of a column in the row.
    Col 1   Col 2   Taken Date  Date 1                  Date 2                
    Date 3
    Data    Data    3/12/2015  3/12/2015 7:22    3/12/2015 8:47   3/12/2015 9:27
    Data    Data    3/22/2015                               3/22/2015 7:27  
    Data    Data    4/12/2015
    We would appreciate any guidance.

    Hi Duane,
    The table and matrix data regions can display complex data relationships by including nested tables,matrices, lists, charts and gauges. Tables and matrices have a tabular layout and their data comes from a single dataset, built on a single data source. The
    key diference between tables and matrices is that tables can include only row groups, where as matrices have row groups and columns groups.
    All Code in this sample are downloadable from
    this URL
    create procedure spMultiple
    as
    begin
    declare @Mytable table ([Col 1] varchar(20),[Col 2] varchar(20),[Taken Date] varchar(20),[Date 1] varchar(20),[Date 2] varchar(20),[Date 3] varchar(20))
    Insert into @Mytable ([Col 1],[Col 2],[Taken Date],[Date 1],[Date 2],[Date 3])
    select * from
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'3/12/2015 7:22' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'3/12/2015 8:47' as [Date 2],'' as [Date 3]
    union all
    Select 'Data' as [Col 1],'Data' as [Col 2],'3/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'3/12/2015 9:27' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'3/22/2015 7:27' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'3/22/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    union all
    select 'Data' as [Col 1],'Data' as [Col 2],'4/12/2015' as [Taken Date],'' as [Date 1],'' as [Date 2],'' as [Date 3]
    ) as temp;
    with Mytable2(
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    as
    SELECT
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    FROM
    (SELECT
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date 1],
    [Date 2],
    [Date 3]
    FROM
    @MyTable) as p
    UNPIVOT
    [Date] FOR [NameDate] IN ([Date 1],[Date 2],[Date 3])
    )AS unpvt
    group by
    [Col 1],
    [Col 2],
    [Taken Date],
    [Date],
    [NameDate]
    Select * from Mytable2 t1 where [date]<>''
    end
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Ricardo Lacerda

  • Selecting from multiple tables, into one internal table

    Hi,
    What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
    Thanks,
    John
    Points will be rewarded and all responses will be highly appreciated.

    I have simple example :
    First one - Join 5 tables
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 4 or 5 tables join.
    get run time field f2.
    f3 = f2 - f1 ( Total time).
    Second one - joins 3 table and use for all entries
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 3 tables join and use for all entries
    get run time field f2.
    f3 = f2 - f1. ( Total time )
    Finally you can have time diffrence between the both sql statement.

  • 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)

Maybe you are looking for

  • Time Capsule disk disconnect and reconnect every 5 minutes

    This problem began with Airport Firmware 7.6, and has continued to perist with every subsequent firmware version.  Reverting to firmware version 7.5.2 eliminates the problem.  Running with the latest firmware version 7.6.3, on OS X 10.8.2, the Time C

  • Cannot open password protected .pdf files?

    I have an ebook for school that requires a username/password combo to open. It of course opens on my computer, but when I try to open it on my Galaxy III, it says there was an error opening the document. It also will not open with my Galaxy Tab 7.0.

  • Doubt in Exception I used

    hi... i created a procedure for deleting a row in a table...and included an exception to handle the error if no data found... it works/display th message if i use raise_application_error...but it is not working when i use predefined exception..i.e No

  • Extracting a Password Protected zip file

    Can anybody help me to extract a password protected zip file? Using java code or any third party API...??

  • PRE7 - clips are shimmering/flickering when an effect is applied

    Hi. When I apply an effect to a clip (Black&White, rotate clip, etc) the clip starts to shimmer/flicker and is not as clear as the original, when i play it. however when i pause or quickly drag the bar through it, it looks normal. will my video come