Groups into Multiple Columns

Post Author: Donamese
CA Forum: General
I am trying to create a report that is split between 3 companies and all states using a distinct count of individuals (as there are duplicates in the data pool).  I would like the report to look like:
State             Company 1                Company 2                 Company 3
AL                       0                                 16                           5
AR                      3                                  9                             4
AZ                       5                                 0                              7
Currently I can only get it to list vertical like:
Company 1
AL       0
AR      3
AZ       5
Company 2
AL     16
etc....
I am unable to get the formating of multiple columns with the grouping.  Is it possible?  And if

Post Author: rookie10
CA Forum: General
Try inserting a Cross Tab in the Report or page header. Its pretty much like a pivot table.
Use State as the Row, Company as the Column, Individuals as Summarized field using Distinct Count as the summary type.
In customized style part of the cross tab you can hide some of the totals and such to get pretty close to the report above - supress subtotals and such.
Hope this works for you. I was pretty excited when I found this feature in Crystal.
Rookie10

Similar Messages

  • Selectively Format Groups with Multiple Columns

    I have a bit of an obscure task I've been trying to hammer out to no avail.  I've searched quite a bit but can't seem to find anyone else who has attempted this.  I have two group by statements, one is a category and the other is a rank.  What I'm trying to do is organize the report so that there are category rows and below each category row is a set of columns for each rank with their associated values as such:
    category1
    rank1     rank2     rank3     rank4
    value1   value1    value1   value1
    value2   value2    value2   value2
    category2
    rank1     rank2     rank3
    value1   value1    value1
    value2   value2    value2
    I've tried using details>Section Expert>>Layout>Format Groups with multiple column.  Unfortunately, this applies to both groups putting the categories into columns instead of rows, making a mess.  Does anyone know of a way to selectively put groups into columns and ensure alignment?  In the above example the user would be able to compare rank values from multiple categories since they all line up.  Any help with this would be very much appreciated.

    Hi,
    Have you tried using a crosstab? Give this a shot:
    1) Group the report on Category
    2) Create a new group header section. Group Header b
    3) Place a crosstab in this section
    4) The columns would be the Rank field, I'm not sure about what you would like to show in the rows
    5) The summarized field would be the Value field ofcourse
    Let me know how this goes.
    -Abhilash

  • How can I separate one column into multiple column?

    How can I separate one column into multiple column?
    This is what I have:
    BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
    0001 PHONE_NUMBER 555-555-0001
    0001 EMAIL [email protected]
    0001 CURRENCY USD
    0002 PHONE_NUMBER 555-555-0002
    0002 EMAIL [email protected]
    0002 CURRENCY USD
    0003 PHONE_NUMBER 555-555-0003
    0003 EMAIL [email protected]
    0003 CURRENCY CAD
    This is what I would like to have:
    BUYER_ID PHONE_NUMBER EMAIL CURRENCY
    0001 555-555-0001 [email protected] USD
    0002 555-555-0002 [email protected] USD
    0003 555-555-0003 [email protected] CAD
    Any help would be greatly appreciated.

    This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
    CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
    then you will type this procedure:
    declare
    phone_number_v varchar2(50);
    EMAIL_v varchar2(50);
    CURRENCY_v varchar2(50);
    cursor my_test is select * from test;
    begin
    for my_test_curs in my_test loop
    select ATTRIBUTE_VALUE INTO phone_number_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='PHONE_NUMBER';
    select ATTRIBUTE_VALUE INTO EMAIL_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='EMAIL';
    select ATTRIBUTE_VALUE INTO CURRENCY_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='CURRENCY';
    INSERT INTO test2
    VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
    END LOOP;
    END;
    Then you will create your final table like this:
    create table final_table as select * from test2 where 1=2;
    After that write this code:
    INSERT ALL
    into final_table
    SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
    FROM TEST2;
    If you have a huge amount of data in your original table this solution may take a long time to do what you need.

  • To display comma separted value into multiple column

    Hi,
    I want to display value into multiple column like below
    data is like this
    col1
    res_menaHome:MenaHome
    res_menaHomeEmp:MenaHome Employee
    res_MDSpecialSer:MD Special Services
    res_Smart:Smart
    now i want to display like
    col1 col2
    res_menaHome MenaHome
    res_menaHomeEmp MenaHome Employee
    res_MDSpecialSer MD Special Services
    res_Smart Smart
    Thanks in advance.

    You mean like this?
    with q as (select 'res_menaHome:MenaHome' myString from dual)
    select substr(myString, 1, instr(myString, ':') - 1) col1,
    substr(myString, instr(myString, ':') + 1) col2
    from q
    COL1,COL2
    res_menaHome,MenaHome

  • Split one column  value and insert into multiple columns

    hi
    am new to plsql .
    i want to split a characters from one column and insert into multiple columns
    i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
    for eg:  before split
    col1 :
    col2 :
    col3 :
    col4 :
    colu5: adsdf,fgrty,erfth,oiunth,okujt
    after split
    col1 :adsd
    col2 :fgrty
    col3 :erfth
    col4 :oiunth
    col5 : adsdf,fgrty,erfth,oiunth,okujt
    can anyone help me
    thanks
    Edited by: 800324 on Dec 23, 2010 8:28 AM
    Edited by: 800324 on Dec 23, 2010 8:36 AM

    How about:
    SQL> create table t
      2  (col1 varchar2(30)
      3  ,col2 varchar2(30)
      4  ,col3 varchar2(30)
      5  ,col4 varchar2(30)
      6  ,col5 varchar2(30)
      7  );
    Table created.
    SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
    1 row created.
    SQL> insert into t (col5) values ('x,y');
    1 row created.
    SQL> insert into t (col5) values ('a,b,c,d');
    1 row created.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
                                                                                                                                adsdf,fgrty,erfth,oiunth,okujt
                                                                                                                                x,y
                                                                                                                                a,b,c,d
    3 rows selected.
    SQL>
    SQL> merge into t a
      2  using ( with t1 as ( select col5||',' col5
      3                       from   t
      4                     )
      5          select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
      6          ,      substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
      7          ,      substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
      8          ,      substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
      9          ,      rtrim(col5, ',') col5
    10          from   t1
    11        ) b
    12  on ( a.col5 = b.col5 )
    13  when matched then update set a.col1 = b.col1
    14                             , a.col2 = b.col2
    15                             , a.col3 = b.col3
    16                             , a.col4 = b.col4
    17  when not matched then insert (a.col1) values (null);
    3 rows merged.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
    adsdf                          fgrty                          erfth                          oiunth                         adsdf,fgrty,erfth,oiunth,okujt
    x                              y                                                                                            x,y
    a                              b                              c                              d                              a,b,c,d
    3 rows selected.
    SQL> Assuming you're on 9i...

  • Split flat file column data into multiple columns using ssis

    Hi All, I need one help in SSIS.
    I have a source file with column1, I want to split the column1 data into
    multiple columns when there is a semicolon(';') and there is no specific
    length between each semicolon,let say..
    Column1:
    John;Sam;Greg;David
    And at destination we have 4 columns let say D1,D2,D3,D4
    I want to map
    John -> D1
    Sam->D2
    Greg->D3
    David->D4
    Please I need it ASAP
    Thanks in Advance,
    RH
    sql

    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
    Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
    Imports System.IO
    Public Class ScriptMain
    Inherits UserComponent
    Private textReader As StreamReader
    Private exportedAddressFile As String
    Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
    Dim connMgr As IDTSConnectionManager90 = _
    Me.Connections.Connection
    exportedAddressFile = _
    CType(connMgr.AcquireConnection(Nothing), String)
    End Sub
    Public Overrides Sub PreExecute()
    MyBase.PreExecute()
    textReader = New StreamReader(exportedAddressFile)
    End Sub
    Public Overrides Sub CreateNewOutputRows()
    Dim nextLine As String
    Dim columns As String()
    Dim cols As String()
    Dim delimiters As Char()
    delimiters = ",".ToCharArray
    nextLine = textReader.ReadLine
    Do While nextLine IsNot Nothing
    columns = nextLine.Split(delimiters)
    With Output0Buffer
    cols = columns(1).Split(";".ToCharArray)
    .AddRow()
    .ID = Convert.ToInt32(columns(0))
    If cols.GetUpperBound(0) >= 0 Then
    .Col1 = cols(0)
    End If
    If cols.GetUpperBound(0) >= 1 Then
    .Col2 = cols(1)
    End If
    If cols.GetUpperBound(0) >= 2 Then
    .Col3 = cols(2)
    End If
    If cols.GetUpperBound(0) >= 3 Then
    .Col4 = cols(3)
    End If
    End With
    nextLine = textReader.ReadLine
    Loop
    End Sub
    Public Overrides Sub PostExecute()
    MyBase.PostExecute()
    textReader.Close()
    End Sub
    End Class
    Put this code in ur script component. Before that add 5 columns to the script component output and name them as ID, col1, co2..,col4. ID is of data type int. Create a flat file destination and name it as connection and point it to the flat file as the source.
    Im not sure whats the delimiter in ur flat file between the 2 columns. I have use a comma change it accordingly.
    This is the output I get:
    ID Col1
    Col2 Col3
    Col4
    1 john
    Greg David
    Sam
    2 tom
    tony NULL
    NULL
    3 harry
    NULL NULL
    NULL

  • Displaying single value (Record) into multiple columns

    Hi All,
    I want to display the single record into multiple columns. Please let me know How to achieve this..
    Record:
    Lvl Activity Acre
    6 Week 4 (Same value to be displayed into 3 columns.)
    REquired output:
    lvl Activity PH1 PH2 PH3
    6 Week 4 4 4
    Thanks
    Kavi

    user533671 wrote:
    Hi,
    Thanks for immediate reply.
    PH1, PH2, PH3, ... will go more columns based on parameter , what we are passing.An single SQL statement cannot have a dynamic number of columns based on the data itself. The projection (columns returned) have to be known before any data is fetched... and that includes some 'parameter' value.
    {thread:id=2309172}
    You can build a query dynamically, based on a parameter or even on the data, but 99 times out 100 people use dynamic queries where they are not needed.
    Perhaps explain to us what you are really trying to achieve and why, and we could suggest some better way.

  • Split one row into multiple columns

    Hi,
    Data in one CLOB column in a table storing with delimiter, ##~~##. Ex. ##~~##abc##~~##defgh##~~##ijklm##~~##nopqr (data starts with delimiter). Please help me to split the data into multiple rows like below and it should be in the same order.
    abc
    defgh
    ijklm
    nopqr
    I am using Oracle 11g.
    Thanks.

    Thanks Hoek for your response. Before posting my question in the forum, I tried similar query. It is working with one character as delimiter.
    with test as (select 'ABC,DEF,GHI,JKL,MNO' str from dual )
    select regexp_substr (str, '[^,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,]+')) + 1;
    Above query is giving correct result by fetching 5 rows. I have modified the query like below...
    with test as (select 'ABC,,,DEF,,,GHI,,,JKL,,,MNO' str from dual )
    select regexp_substr (str, '[^,,,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,,,]+')) + 1;
    Above query resulting 13 rows and last 8 rows are nulls. Number of null rows are increasing, if I increase number of characters in delimiter. Could you please tell me how to avoid those null rows.
    Thanks.

  • Split 1 column into multiple columns

    Hi
    How can we acheive this in Sql:
    Col 1
    abc def ghi jkl
    convert to:
    Col 1
    Col 2
    Col 3
    Col 4
    abc
    def
    ghi
    jkl
    Royal Thomas

    The best approach is to NOT split them out into individual columns... It violates the 1st normal form...
    Under first normal form, all occurrences of a record[sic] type must contain the same number of fields[sic].
    First normal form excludes variable repeating fields[sic] and groups.
    The better approach is to split them into rows, in their own table, with a foreign key reference back to the table you are pulling them away from.
    If you check my 1st post you'll see that I split the string with a function. That same a function can be used to populate the new table.
    Something along these lines...
    IF OBJECT_ID('tempdb..#BadOldDesign') IS NOT NULL
    DROP TABLE #BadOldDesign;
    CREATE TABLE #BadOldDesign (
    ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
    ListOfCodes VARCHAR(100) NOT NULL
    INSERT #BadOldDesign (ListOfCodes) VALUES
    ('abc htr tbj yfd hjk mth'),
    ('bbb hyt tbj vyk hjk htd'),
    ('vvv nud'),
    ('yyy hyn tbj bdr '),
    ('htr htf tbj yfd hjk mko'),
    ('kio bhn tbj bjd hjk'),
    ('byd loj tbj yfd hjk cds');
    SELECT * FROM #BadOldDesign bod
    IF OBJECT_ID('tempdb..#ShinyNewTable') IS NOT NULL
    DROP TABLE #ShinyNewTable;
    SELECT
    bod.ID,
    sc8.ItemNumber,
    sc8.Item
    INTO #ShinyNewTable
    FROM
    #BadOldDesign bod
    CROSS APPLY dbo.SplitCSVToTable8K(bod.ListOfCodes, ' ') sc8;
    ALTER TABLE #ShinyNewTable ALTER COLUMN id INT NOT NULL;
    GO
    ALTER TABLE #ShinyNewTable ALTER COLUMN ItemNumber INT NOT NULL;
    GO
    ALTER TABLE #ShinyNewTable ADD CONSTRAINT pk_ShinyNewTable PRIMARY KEY CLUSTERED (ID, ItemNumber);
    SELECT * FROM #ShinyNewTable snt
    The dbo.SplitCSVToTable8K function that I'm using can be found here... http://www.sqlservercentral.com/articles/Tally+Table/72993/
    HTH,
    Jason
    Jason Long

  • Display rows into multiple columns

    I have a table in the following format:
    id value
    a1 0
    a2 0
    a3 0
    a4 0
    b1 0
    b2 0
    b3 0
    b4 0
    how do I go about displaying it into four columns in the following format:
    id1 value1 id2 value2
    a1 0 b1 0
    a2 0 b2 0
    a3 0 b3 0
    a4 0 b4 0

    Hi,
    789063 wrote:
    I got that error in toad. So now I am testing from command prompt. When you say "command prompt", do you mean SQL*Plus?
    Sorry, I don't know much about Toad. If Toad is returning 0 rows, and the same query is returning 8 rows in SQL*Plus, then I suspect you are not connecting to the same database or the same user. ASre you sure you're running the exact same query in both front ends?
    Here is the data set that I am testing for:
    <pre>
    id1 value
    smple_val_1 0
    smple_val_2 1
    smple_val_3 1
    smple_val_4 2
    smple_other_1 3
    smple_other_2 5
    smple_other_3 8
    smple_other_4 13
    some_other_val1 1
    some_other_val2 0
    some_other_val3 3
    some_other_val4 5
    </pre>
    I am trying to select only 'smple%' in the query, which should display in four columns like:
    <pre>
    id1 val1 id2 val2
    smple_val_1 1 smple_other_1 3
    smple_val_2 0 smple_other_2 5
    smple_val_3 0 smple_other_3 8
    smple_val_4 2 smple_other_4 13
    </pre>Is that really the output you want? Why not
    ID1             VAL1 ID2             VAL2
    smple_val_1        0 smple_other_1      3
    smple_val_2        1 smple_other_2      5
    smple_val_3        1 smple_other_3      8
    smple_val_4        2 smple_other_4     13with the 0's and 1's in the val1 column reversed?
    Here is the ddl I used:
    <pre>
    CREATE TABLE     table_x
    ( id     VARCHAR2 (20)     PRIMARY KEY
    , value     NUMBER
    INSERT INTO table_x (id, value) VALUES ('smple_val_1', 0);
    INSERT INTO table_x (id, value) VALUES ('smple_val_2', 1);
    INSERT INTO table_x (id, value) VALUES ('smple_val_3', 1);
    INSERT INTO table_x (id, value) VALUES ('smple_val_4', 2);
    INSERT INTO table_x (id, value) VALUES ('smple_other_1', 3);
    INSERT INTO table_x (id, value) VALUES ('smple_other_2', 5);
    INSERT INTO table_x (id, value) VALUES ('smple_other_3', 8);
    INSERT INTO table_x (id, value) VALUES ('smple_other_4', 13);
    INSERT INTO table_x (id, value) VALUES ('some_other_val1', 1);
    INSERT INTO table_x (id, value) VALUES ('some_other_val2', 0);
    INSERT INTO table_x (id, value) VALUES ('some_other_val3', 3);
    INSERT INTO table_x (id, value) VALUES ('some_other_val4', 5);
    </pre>Thanks, that's good.
    Where is the explanation of how you get the results you want from that data? There are a lot of different ways to get the same results from the same data, especially from a small set of sample data. I might provide a query that gets the right results for the wrong reasons, and when you run that query on a different set of data, it won't necessarily work. That's exactly what happened before. I guessed at what you wanted, but I guessed wrong. Guessing is not a very efficient or reliable way to solve problems. Don't make people guess: explain what you want.
    In particular, explain how you can tell, buy looking at a row and column in the original table, to which row and which column of the output it corresponds. I'm pretty sure that the id column of the table always corresponds to either the id1 or idl2 column of the output, and that value always corresponds to either val1 or val2. From this latest set of sample data, it looks like all the rows in table_x that start with 'smple_val' will correspond to the id1 and val1 columns, and that all therows that start with 'smple_other_' will correspond to the id2 and val2 columns. It also looks like each row of the output represents a unique value of the last character of table_x.id.
    If I guessed right this time, then what you want is:
    SELECT       MIN (CASE WHEN id LIKE 'smple\_val\_%'   ESCAPE '\' THEN id    END)     AS id1
    ,       MIN (CASE WHEN id LIKE 'smple\_val\_%'   ESCAPE '\' THEN value END)     AS val1
    ,       MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN id    END)     AS id2
    ,       MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN value END)     AS val2
    FROM       table_x
    GROUP BY  SUBSTR (id, -1)
    ORDER BY  SUBSTR (id, -1)
    ;But this is only a guess. I can't guarrantee that this will work on your real data any better than my last guess did. You'll get better answers faster if you provide an explanation, so that poeple don't have to guess so much.

  • Page caption text won't flow into multiple columns : LR4 book module

    Hi,
    I'm in process of creating a photobook using LR4's Book Module. Whenever I create a multiple columns page or photo caption, the text won't flow from the 1st column into the suceeding column... does this happen to anybody else. The multiple columns feature however does work for normal text placeholders.

    Dorin,
    You guess right but that's not very useful to me because sometimes I just want to have a few lines of text at the bottom or at the top of the photo but in 2 or 3 columns for easier reading. I can do that with text placeholders like the one below and the ability to do that with page or photo caption would be desirable too.

  • How to insert parameter value into multiple columns and rows

    Hi All,
    I have one procedure insert_tab and I am passing
    100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
    Table:
    Col1 Col2 Col3
    100 101 102
    103 104 105
    106 107 108
    Awaiting for your reply..

    That's not more clear for me...
    Anyway, if you really want a procedure for that, try :
    SQL> create table tblstr (col1 number,col2 number,col3 number);
    Table created.
    SQL>
    SQL> create or replace procedure insert_fct (p_string IN varchar2)
      2  as
      3  v_string     varchar2(4000):=p_string||':';
      4  v_substring  varchar2(4000);
      5 
      6  begin
      7      while instr(v_string,':') > 0 loop
      8            v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
      9            insert into tblstr(col1,col2,col3)
    10            values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
    11                    substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
    12                    substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
    13            v_string:=substr(v_string,instr(v_string,':')+1);
    14      end loop;
    15  end;
    16  /
    Procedure created.
    SQL>
    SQL> show err
    No errors.
    SQL>
    SQL> select * from tblstr;
    no rows selected
    SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
    SQL> exec insert_fct('109~~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~110~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~~111')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
           109
                      110
                                 111
    6 rows selected.
    SQL> Nicolas.

  • To split a column into multiple columns

    Hi,
    I have column and i want to split it into three columns as shown below given inputs and required outputs. I have written this query to get P_1, and p_2 but dont know how to get p_3.
    SELECT ADDRESS,SUBSTR(ADDRESS,1, INSTR(ADDRESS,' ')-1) P_1
         ,SUBSTR(ADDRESS, instr(address,' ',-1)+1) P_2
         FROM TT
    Input:
    ADDRESS     
    1 AVENUE OF THE AMERICAS     
    2 NORTH CAROLINE STREET EAST     
    236 TURPENTINE ROAD COOPER CREEK     
    REQUIRED OUTPUT
    P_1     P_2     P_3     
    1     AMERICAS     AVENUE OF THE
    2     EAST     NORTH CAROLINE STREET
    236     CREEK     TURPENTINE ROAD COOPER
    Thanks in advance

    If you're on 10g or 11g you can do something like this ...
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 4 21:18:07 2008
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    column p_1 format a3
    column p_2 format a10
    column p_3 format a30
    with data as
    select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
    select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
    select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
    select
      regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\1' ) as p_1 ,
      regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\3' ) as p_2 ,
      regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
    from
      data
    P_1 P_2        P_3
    1   AMERICAS   AVENUE OF THE
    2   EAST       NORTH CAROLINE STREET
    236 CREEK      TURPENTINE ROAD COOPER
    3 rows selected.
    -- or try this shorter version --
    with data as
    select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
    select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
    select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
    select
      regexp_replace( address, '^([^ ]+).*', '\1' ) as p_1 ,
      regexp_replace( address, '.*?([^ ]+)$', '\1' ) as p_2 ,
      regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
    from
      data
    P_1 P_2        P_3
    1   AMERICAS   AVENUE OF THE
    2   EAST       NORTH CAROLINE STREET
    236 CREEK      TURPENTINE ROAD COOPER
    3 rows selected.See SQL Snippets: SQL Features Tutorials - Regular Expressions if you're unfamiliar with regular expressions.
    If you can't / don't want to use regular expressions then you'll need to settle for a more boring approach like this one.
    with data as
    select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
    select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
    select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
    select
      substr( address, 1, instr( address, ' ' ) - 1 ) as p_1 ,
      substr( address, instr( address, ' ', - 1 ) + 1 ) as p_2 ,
      substr
      ( address,
        instr( address, ' ', + 1 ) + 1,
        instr( address, ' ', - 1 ) - instr( address, ' ' ) - 1
      ) as p_3
    from
      data
    P_1 P_2        P_3
    1   AMERICAS   AVENUE OF THE
    2   EAST       NORTH CAROLINE STREET
    236 CREEK      TURPENTINE ROAD COOPER--
    Joe Fuda
    SQL Snippets

  • Group by multiple columns problem

    I am having some problems with my query. For example:
    SELECT STUDENTNUMBER FROM REGISTRATION
    WHERE TERM='A1' AND YEAR=2008
    GROUP BY STUDENTNUMBER
    HAVING COUNT( COURSECODE) = 1;
    which returns:
    STUDENTNUMBER
    123456
    789012
    6 rows selected
    Which is ok, but the problem is i want to list out not only studentnumber but also the coursecode,year and the term of students. But if i do this:
    SELECT STUDENTNUMBER,COURSECODE,YEAR,TERM,
    FROM REGISTRATION WHERE TERM='A1'AND YEAR=2008
    GROUP BY (STUDENTNUMBER,COURSECODE,YEAR,TERM)
    HAVING COUNT( COURSECODE) = 1;
    i got 50+ records in which most of them are duplicates!. To put it shortly i want the 6 records but with the coursecode,year,studentnumber and term listed. is there a workaround for this?

    Thanks everyone for your suggestion!
    I end up using Arun's query but modify it slightly to this:
    SELECT STUDENTNUMBER,COURSECODE,YEAR,TERM
    FROM REGISTRATION WHERE STUDENTNUM IN(
    SELECT STUDENTNUMBER FROM REGISTRATION
    WHERE TERM='A1' AND YEAR=2008
    GROUP BY STUDENTNUMBER
    HAVING COUNT(COURSECODE) = 1) AND TERM='A1' AND YEAR=2008;
    Using the multiple set functions would also yields the same result.Anyway i would post the create table statements and insert statements for everyone's references.
    CREATE TABLE REGISTRATION(
         CourseCode     VARCHAR(15)     NOT NULL     ,
         Year          NUMBER(4)     NOT NULL     ,
         Term          VARCHAR(5)     NOT NULL     ,
         StudentNumber     NUMBER(12)     NOT NULL     ,
         Lecturer          NUMBER(12)     NOT NULL     ,
         Grade          NUMBER(5,2)               ,
         CONSTRAINT REGISTRATION_PKEY PRIMARY KEY(CourseCode, Year, Term, StudentNumber, Lecturer),
         CONSTRAINT REGISTRATION_FKEY1 FOREIGN KEY(CourseCode) REFERENCES COURSE(CourseCode),
         CONSTRAINT REGISTRATION_FKEY2 FOREIGN KEY(StudentNum) REFERENCES STUDENT(StudentNumber),
         CONSTRAINT REGISTRATION_FKEY3 FOREIGN KEY(Lecturer) REFERENCES ACADSTAFF(StaffNum)
    Insert statements:
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A1',1292601,2001,null);
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A2',8290012,2001,null);
    INSERT INTO REGISTRATION VALUES('CSE235',2008,'A2',7246935,2002,null);
    I want to list the student number, coursecode, year and term of students who registers for only one course in term "A1" in 2008.The result:
    STUDENTNUM COURSECODE YEAR TERM
    3000911 CSE101 2008 A1
    3335010 CSE101 2008 A1
    3011724 CSE101 2008 A1
    8754117 CSE101 2008 A1
    1032858 CSE101 2008 A1
    3292880 CSE101 2008 A1
    6 rows selected.
    Edited by: user12231119 on Nov 16, 2009 9:19 PM

  • How to insert signals into multiple columns in db, dbtoolset

    I have  a labVIEW program that is currenly simulating voltage and a current signal using the DAQ Assistant. I'm using the database connectivity toolset. I am currently able to insert one signal into the database converted to a float(I can insert both into the same column as bianary but it needs to be stored as a usable format and in seperate columns.)
    The problem I am having is at the DB Tools Insert Data block. I have the connection, dbTable, error code, and create table boolean being passed into it. Where I am a little lost is how to set the columns I want to store the multiple signals into.
    If someone could break that part down for me that would be great. In short, I want to store voltage(channel0) and current(channel1) from the DAQ Assistant into their own respective columns in the db.

    As I have often pointed out, the easiest solution to this situation is to dump the Database Connectivity Toolkit. Check out this thread and follow the references in it. If the DCT weren't in the way what you are wanting to do would be very easy.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

Maybe you are looking for

  • Load monthly excel data in xcelsius

    Hi, I have 12 month of data for 35 KPI in excel sheet which needs to be updated every month when new data comes. I need to design a dashboard in xcelsius, can you please help me how can i design the architecture for this dashboard so that when excel

  • Playing movie created in iMovie on PC

    Hello, I have a client I'm making a marketing presentation for. I wanted to do it in iMovie instead of PowerPoint so I can integrate video & sound with the still photos and text. The big question is if I make it in iMovie can my client open it on a P

  • Moving IWEB from one MacBook to MacBook Pro

    Hello - Just purchased new MacBook Pro. I was told to buy the firewall cable and just push "T" and everything would transfer. This was not really true. Things ended up in a muddle. One problem is the IWEB. It did not transfer with all blog entries. T

  • HT204053 Stupid question, but how do I get to/access my iCloud?!

    Stupid question, but how do I get to/access my iCloud? All this time, I've been under the impression that every time I plug in & lock my screen, things on my phone are backed up in my cloud, but I've never been able to find it to check! And, yes, I'm

  • Software Alternativ​e to the NEAT Scanning System

    Hi, I just purchased the HP Officejet Pro 8600 Plus. It seems like it is going to be a good printer. I have also been thinging about one of the NEAT document scanning and filing system.  I am wondering if there is software available to use with the 8