Row to Column Conversion Question

Hi All,
           Could you please help on this sql query statement:
SELECT BENEFIT FROM TEST_T ;
BENEFIT
QO,1G,1U,1W
Out Put Needed like this
BENEFIT
QO
1G
1U
1W
Thanks,

Hi,
As I said, it depends on your data, your requirements and your version.
REGEXP_COUNT was new in Oracle 11.1.  Since you're using an earlier version, you can see how many comma-delimited sub-strings you have by seeing how much shorter the string gets if you remove all the commas:
1 + LENGTH (benefit)
  - LENGTH (REPLACE (benefit, ','))
This assumes you don't have data with mutiple consecutive commas such as 'AB,,,,CD', but it might not cause any terrible results even if you do.
The way I used CONNECT BY won't work in Oracle 10, either.
Now I know everything I need to know about your Oracle version, but I don't know anything about your data or your requirements.  Do you want me to spend my time writing solutions that assume things about your data and your requirments, so you can spend your time trying them only to see that they don't do what you need?
Explain what your data is like.  Do you have a fixed number of comma-delimited parts (e.g., always 4 parts).  If not, do you have an upper bound (e.g., never more than 10 parts)?  Can you have multiple consecutive commas?
Explain what you need to get from that data.  Will you always be splitting one string into parts, as in the example you posted, or will you need to split multiple stings in the same query?  Will the correct results ever contain NULL?
Post a little sample data (CREATE TABLE and INSERT statements), showing all special cases you need to handle.  Post the results you want from that data.
See the forum FAQ: https://forums.oracle.com/message/9362002

Similar Messages

  • Row to Column conversion

    Hi,
    i am having following table
    SELECT* FROM Col_to_row;
    output is:
    A      B      C
    X      Y      Z
    1      2      3
    i want to write query for below output, need to convert row into column for n number of rows for example i have taken only 3 rows:
    A X 1
    B Y 2
    C Z 3

    Three things to notice in this solution:
    1) I am ordering by the original column name. You may want to order by something else.
    2) When pivoting, you must indicate the name, number and datatype of the columns, so if there is a fourth line of input you have to add a column to the query.
    3) This works on Oracle 11GR1 and above. Next time, be sure to indicate your Oracle version from the start.create table COL_TO_ROW(C1, C2, C3) as select
    'A', 'B', 'C' from DUAL union all select
    'X', 'Y', 'Z' from DUAL union all select
    '1', '2', '3' from dual;
    select * from (select rownum rn, a.* from COL_TO_ROW a)
    UNPIVOT(VAL for COL in(C1, C2, C3))
    PIVOT(max(VAL) for RN in (1,2,3))
    order by col;
    COL 1 2 3
    C1  A X 1
    C2  B Y 2
    C3  C Z 3

  • Row break + column header Question

    I've got two question i can't find out by myself.
    Question 1:
    I use a row break on the first column of my report. That workd correctly. But how do i get a line or a empety row after the break? I prefer a line...
    Question 2:
    I want to have an extra header above some columns. how to create that. A example:
    extra header 1 extra header 2
    column1 column2 column3 column4 column5 column6 column7
    hope someone can help me with this... tnx in advanced

    Hi,
    For your second question, you could create a custom template and put in the additional headers in there, under the 'Before Column Heading' section. I have done this with one of my reports where I simply copied the standard template and changed it to include the header information. This is an example of what I have in the Before Column Heading section for my custom template.
    <tr><th class="t18ReportHeader"#ALIGNMENT# colspan="4" style="font-weight:bold;text-align:center;">Progress Data </th></tr>
    <tr><th class="t18ReportHeader"#ALIGNMENT#> </th>
    <th class="t18ReportHeader"#ALIGNMENT# style="font-weight:bold;text-align:center;" colspan="4"> Header 1 </th>
    <th class="t18ReportHeader"#ALIGNMENT# colspan="5" style="font-weight:bold;text-align:center"> Header 2 </th>
    <th class="t18ReportHeader"#ALIGNMENT# colspan="4" style="font-weight:bold; text-align:center"> Header 3</th>
    HTH,
    Chandini

  • Rows to column conversion

    Hi,
    I know this question has been asked couple of times but I could not understand from them hence posting my query here.
    I have a table named XYX
    id attr_cd value
    1 ABC 1000
    1 PQR 2000
    1 XDR 1500
    2 PQR 1405
    2 ABC 1254
    etc
    My reqt is to write a procedure which will accept ID as i/o parameter and will populate another temp table temp as
    id ABC XDR PQR
    1 1000 1500 200
    2 1254 1405
    like that.
    Please comeone suggest a SIMPLE way to do that.
    Thanks in advance
    Aashish

    Could you please provide a simple code which can be understood?Not sure if it can be understood, but for academical reasons it might be useful ;)
    SQL>  with t as (
    select 1 id, 'ABC' attr_cd, 1000 value from dual union all
    select 1,    'PQR',         2000       from dual union all
    select 1,    'XDR',         1500       from dual union all
    select 2,    'PQR',         1405       from dual union all
    select 2,    'ABC',         1254       from dual
    select id,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="ABC"]/@VALUE') abc,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="PQR"]/@VALUE') pqr,
           extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="XDR"]/@VALUE') xdr
      from t group by id
      ID ABC        PQR        XDR      
       1 1000       2000       1500     
       2 1254       1405                
    2 rows selected.

  • Rows to Column Conversion in ABAP

    Hello guys,
    I wanted to create a report in which I need to convert rows in to column.
    e.g.
    I have a itab_col which contains my column header as follows.
    itab_col-plant        itab_col-name
    1000                     Plant A
    2000                     Plant B
    3000                     Plant C    
    I have a itab_data which contains my data as follows .
    itab_data-date    itab_data-qty       itab_data-plant
    01.06.2006           10                  1000
    01.06.2006           20                  1000
    01.06.2006           50                  2000
    02.06.2006           20                  3000
    I need to print the report as follows
      Date       Plant A      Plant B      Plant C
    01.06.2006     30           50           0
    02.06.2006     0            0            20
    Could you tell me how I can do it in abap.

    Hi,
    first create table with following attribute.
    table_row_to_column
    1. date
    2. Plant A
    3. Plant B
    4. Plant C.
    .............D E F ..number of plant possible.
    Sum Up The data
    01.06.2006 10 1000
    01.06.2006 20 1000
    01.06.2006 50 2000
    02.06.2006 20 3000
    01.06.2006 30 1000
    01.06.2006 50 2000
    02.06.2006 20 3000
    to new data_table_sum_value
    <b>for that u have to</b>
    1) Sort the table date & plant.
    2) sum up records for similar plant based on date
    <b>Convert rows in to column.</b>
    loop at data_table_sum_value.
      case data_table_sum_value-plant.
        when 1000.
           table_row_to_column-plant_A = data_table_sum_value-qnty.
        when 2000.
           table_row_to_column-plant_B = data_table_sum_value-qnty.
        when 3000.
           table_row_to_column-plant_C = data_table_sum_value-qnty.
        when 4000.
           table_row_to_column-plant_D = data_table_sum_value-qnty.
        when 5000.
           table_row_to_column-plant_E = data_table_sum_value-qnty.
      endcase.
       at end of date.
         append table_row_to_column.
       endat.
    endloop.
    <b>Please Mark Helpful Answers & Rewards Points.
    Dont Forget to mark as problem solved if solved</b>
    Regards

  • Row to column conversion during excel download

    Dear Experts,
    I have an internal table with one column.
    It has some entries say ten.
    I want this ten rows of entries to be displayed in the excel sheet as a single row. It means each row entry of the internal table should fit in to each cell.
    Is there any possibility with GUI_DOWNLOAD FM to do this?
    If not, then how could i do that?
    Please let me know its urgent.
    Regards,
    Shashi

    Hi,
    i m not aware of whether it can be done through FM 'GUI_DOWNLOAD' but i have one sugeestion.
    You can first transpose your internal table and then download it.
    Sample code for obtaining the transpose is as follows:
    *& Report Z_TRANPOSEALV *
    *& Author : Swarna.S.
    *& AS: This simple ALV report display is in a transposed way
    *& Publised at ****************
    REPORT Z_TRANSPOSEALV .
    Type pools declaration for ALV
    TYPE-POOLS: slis.
    *Declarations for ALV, dynamic table and col no for transpose
    DATA: l_col TYPE sy-tabix,
    l_structure TYPE REF TO data,
    l_dyntable TYPE REF TO data,
    wa_lvc_cat TYPE lvc_s_fcat,
    lt_lvc_cat TYPE lvc_t_fcat,
    lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
    wa_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv,
    lt_layout TYPE slis_layout_alv.
    *Field symbols declarations
    FIELD-SYMBOLS :
    <header> TYPE ANY,
    <dynheader> TYPE ANY,
    <dyndata> TYPE ANY,
    <ls_table> TYPE ANY,
    <dynamictable> TYPE STANDARD TABLE,
    <it_table> TYPE STANDARD TABLE.
    *Input the name of the table
    PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY.
    *Initialization event
    INITIALIZATION.
    *Start of selection event
    START-OF-SELECTION.
    Create internal table of dynamic type
    CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
    WITH NON-UNIQUE DEFAULT KEY.
    ASSIGN l_dyntable->* TO <it_table>.
    *select statement to select data from the table as input into
    *our dynamic internal table.
    *Here i have restricted only till 5 rows.
    *You can set a variable and give no of rows to be fetched
    *The variable can be set in your select statement
    SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
    FROM (p_table) up to 5 rows.
    *Fieldcatalogue definitions
    wa_lvc_cat-fieldname = 'COLUMNTEXT'.
    wa_lvc_cat-ref_table = 'LVC_S_DETA'.
    APPEND wa_lvc_cat TO lt_lvc_cat.
    wa_fieldcat-fieldname = 'COLUMNTEXT'.
    wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
    wa_fieldcat-key = 'X'..
    APPEND wa_fieldcat TO lt_fieldcat.
    DESCRIBE TABLE <it_table>.
    DO sy-tfill TIMES.
    For each line, a column 'VALUEx' is created in the fieldcatalog
    Build Fieldcatalog
    WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
    CONCATENATE 'VALUE' wa_lvc_cat-fieldname
    INTO wa_lvc_cat-fieldname.
    wa_lvc_cat-ref_field = 'VALUE'.
    wa_lvc_cat-ref_table = 'LVC_S_DETA'.
    APPEND wa_lvc_cat TO lt_lvc_cat.
    Build Fieldcatalog
    CLEAR wa_fieldcat.
    wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
    wa_fieldcat-ref_fieldname = 'VALUE'.
    wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
    APPEND wa_fieldcat TO lt_fieldcat.
    ENDDO.
    Create dynamic internal table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = lt_lvc_cat
    IMPORTING
    ep_table = l_dyntable. ASSIGN l_dyntable->* TO <dynamictable>.
    Create structure as structure of the internal table
    CREATE DATA l_structure LIKE LINE OF <dynamictable>.
    ASSIGN l_structure->* TO <header>.
    Create structure = structure of the internal table
    CREATE DATA l_structure LIKE LINE OF <it_table>.
    ASSIGN l_structure->* TO <ls_table>.
    Create field catalog from our table structure
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    i_structure_name = p_table
    CHANGING
    ct_fieldcat = lt_fieldcatalogue
    EXCEPTIONS
    inconsistent_interface = 1
    program_error = 2
    OTHERS = 3.
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF. DESCRIBE TABLE lt_fieldcatalogue.
    Fill the internal to display <dynamictable>
    DO sy-tfill TIMES.
    IF sy-index = 1.
    READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
    ENDIF.
    For each field of it_table
    ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
    Fill 1st column
    <dynheader> = wa_fieldcat-seltext_m.
    IF <dynheader> IS INITIAL.
    <dynheader> = wa_fieldcat-fieldname.
    ENDIF.
    *Filling the other columns
    LOOP AT <it_table> INTO <ls_table>.
    l_col = sy-tabix + 1.
    ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
    <dynheader>.
    IF sy-subrc NE 0. EXIT .ENDIF.
    WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
    ENDLOOP.
    APPEND <header> TO <dynamictable>.
    ENDDO.
    *Layout for ALV output
    lt_layout-zebra = 'X'.
    lt_layout-no_colhead = 'X'..
    lt_layout-colwidth_optimize ='X'.
    lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.
    *ALV Grid output for display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    is_layout = lt_layout
    it_fieldcat = lt_fieldcat
    TABLES
    t_outtab = <dynamictable>.
    Regards,
    Karuna.

  • Row to column conversion in large result set

    I need to get the differnt levels of alerts for each user, with the total alert counts and counts for each type of alert.
    SELECT COUNT(*) TOTAL,
            u.name,
            d.deptname,
            COUNT(CASE WHEN al.severity = 5 THEN 1 END) INDETERMINATE,
            COUNT(CASE WHEN al.severity = 4 THEN 1 END) WARNING,
            COUNT(CASE WHEN al.severity = 3 THEN 1 END) MINOR,
            COUNT(CASE WHEN al.severity = 2 THEN 1 END) MAJOR,
            COUNT(CASE WHEN al.severity = 1 THEN 1 END) CRITICAL
    FROM alerts al, user u, dept d
    WHERE al.userid = u.userid
      AND u.deptid = d.deptid
      AND al.time = sysdate - 4/24
      AND al.time <= sysdate
    GROUP BY u.name, d.deptname  This might be inefficient especially when the amount of data is huge and potentially you could be looking at millions of rows in a given interval. So I was thinking of grouping by severity, which would eliminate the CASE statements, but then the problem on group by is that I get it as a rows instead of columns.
    Would anyone have a suggestion as to do it effeciently especially one that has millions of rows? Thanks.

    I guess eventually we are probably going to move towards that, but using a staright forward query is the immediate solution and any help on that would be great. Thanks.

  • Reg:Row to column conversion

    Hi All,
    I will give string three string values in a single variable like CNTNS_VAL_STR = test,value,small
    but i need result like
    test
    value
    small
    Please help to reslove the one
    thanks,

    Your requirement isn't very clear anymore.
    Please post a small testcase, like I did below, assuming you're looking for a way to query column values based on an input string:
    SQL> create table t as
      2  select 1 rn,'A' descr from dual union
      3  select 2,'B' from dual union
      4  select 3,'C' from dual union
      5  select 4,'Q' from dual union
      6  select 5,'X' from dual;
    Table created.
    SQL> select * from t;
            RN D
             1 A
             2 B
             3 C
             4 Q
             5 X
    5 rows selected.
    SQL> create or replace function str2tbl( p_str in varchar2, p_delim in varchar2 default ',' )
      2  return sys.odcivarchar2list
      3  pipelined
      4  as
      5      l_str long default p_str || p_delim;
      6      l_n   number;
      7  begin
      8      loop
      9          l_n := instr( l_str, p_delim );
    10          exit when (nvl(l_n,0) = 0);
    11          pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );
    12          l_str := substr( l_str, l_n+1 );
    13      end loop;
    14      return;
    15  end;
    16  /
    Function created.
    SQL> select *
      2  from   t
      3  where descr in ( select column_value
      4                   from   table(str2tbl('A,B,C'))
      5                 );
            RN D
             1 A
             2 B
             3 C
    3 rows selected.
    So, I more or less 'joined' a table to a pipelined function (no cursor needed) based on an input string.
    If you search for 'str2tbl' on http://asktom.oracle.com then you'll find many more examples.

  • Row and Column transpose question

    Dear Support ,
    I would like to transpose one internal table , for example :
    Column : MATERIAL , QTY , DATE
                  MA1          ,  100  , 2009-01-01
                  MA2          ,  200  , 2009-01-01
                  MA3          ,  200  , 2009-03-02
    After the convertion , it should be like that :
    Column : MATERIAL , 2009-01-01 , 2009-03-02
                  MA1            100                0
                  MA2             200               0
                  MA3             0                200
    As i know , in SQL it is very easy to do that , just like :
    select sum(case ' xxx ' when ' xxx ' .... ) ....
    But how to do that in ABAP ?
    Thanks .
    Carlos Zhang

    Hi,
    Please find teh code as follows
    TYPES : BEGIN OF t_itab,
             mat TYPE matnr,
             qty TYPE menge_d,
             dat TYPE datum,
            END OF t_itab.
    TYPES : BEGIN OF t_datcol,
             dat TYPE datum,
             col TYPE i,
            END OF t_datcol.
    DATA : tbl_obj  TYPE REF TO data,
           line_obj TYPE REF TO data.
    DATA : lv_field TYPE fieldname.
    DATA : wa     TYPE t_itab,
           wa_col TYPE t_datcol.
    DATA: itab    TYPE STANDARD TABLE OF t_itab,
          itab_dt TYPE STANDARD TABLE OF t_datcol.
    DATA : fcat TYPE lvc_t_fcat.
    DATA : fcat_wa TYPE lvc_s_fcat.
    DATA: cntr TYPE i.
    FIELD-SYMBOLS : <fs>          TYPE t_datcol,
                    <fs_mainitab> TYPE STANDARD TABLE,
                    <fs_line>     TYPE ANY,
                    <fs_field>    TYPE ANY.
    wa-mat = 'M1'.
    wa-qty = 100.
    wa-dat = '20090101'.
    APPEND wa TO itab.
    wa_col-dat =  '20090101'.
    APPEND wa_col TO itab_dt.
    wa-mat = 'M2'.
    wa-qty = 200.
    wa-dat = '20090101'.
    APPEND wa TO itab.
    wa_col-dat =  '20090101'.
    APPEND wa_col TO itab_dt.
    wa-mat = 'M3'.
    wa-qty = 200.
    wa-dat = '20090302'.
    APPEND wa TO itab.
    wa_col-dat =  '20090302'.
    APPEND wa_col TO itab_dt.
    SORT itab_dt BY dat.
    DELETE ADJACENT DUPLICATES FROM itab_dt COMPARING dat.
    fcat_wa-fieldname = 'MAT'.
    fcat_wa-ref_field = 'MATNR'.
    fcat_wa-ref_table = 'MARA'.
    APPEND fcat_wa TO fcat.
    LOOP AT itab_dt assigning <fs>.
      <fs>-col = sy-tabix.
      CONCATENATE 'F_' <fs>-dat INTO lv_field.
      fcat_wa-fieldname = lv_field.
      fcat_wa-ref_field = 'MENGE'.
      fcat_wa-ref_table = 'MSEG'.
      APPEND fcat_wa TO fcat.
    ENDLOOP.
    now make your main internal table as required
    dynamic table only incase if you do not know the dates
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog           = fcat
      IMPORTING
        ep_table                  = tbl_obj
      EXCEPTIONS
        generate_subpool_dir_full = 1
        OTHERS                    = 2.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ASSIGN tbl_obj->* TO <fs_mainitab>.
    CREATE DATA line_obj LIKE LINE OF <fs_mainitab>.
    ASSIGN line_obj->* TO  <fs_line> .
    IF <fs_mainitab> IS ASSIGNED AND <fs_line> IS ASSIGNED.
      LOOP AT  itab INTO wa.
        ASSIGN COMPONENT 'MAT' OF STRUCTURE <fs_line> TO <fs_field>.
        IF <fs_field> IS ASSIGNED.
          <fs_field> = wa-mat.
          UNASSIGN <fs_field> .
          READ TABLE itab_dt INTO wa_col
          WITH KEY dat = wa-dat.
          IF sy-subrc EQ 0.
            cntr = wa_col-col + 1.
            ASSIGN COMPONENT cntr OF STRUCTURE <fs_line> TO <fs_field>.
            IF <fs_field> IS ASSIGNED.
              <fs_field> = wa-qty.
              COLLECT <fs_line> INTO <fs_mainitab>.
              UNASSIGN <fs_field> .
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.
    Regards,
    Ankur Parab
    Edited by: Ankur Parab on Jun 24, 2009 4:04 PM

  • Rows to Columns conversion in an Internal Table

    Hello All,
    I have data like below:
    Matnr1  ABC  100
    Matnr1  ABC  200
    Matnr1  ABC  500
    Matnr2  XYZ   300
    Matnr2  XYZ   600
    I want data like this:
    Matnr1  ABC  100  200  500
    Matnr2  XYZ   300  600
    Is it possible?  If yes, could anybody help achieving this?
    Thanks a lot in advance.
    Ajay

    Hi Ajay,
      Try this.
    ( this is temp table for your formate)
    data: begin of itab1 occurs 10,
          line(150),
         end of itab1.
    Sort itab by col1 col2.  ( Here itab is your table )
    loop at itab.
    at new col2.
      write: / itab-col1,
                 itab-col2.
      concatenate itab-col1
                        itab-col2
               into  itab1.
    endat.
      write  itab-col3.
      concatenate itab1
                        itab-col3
        into itab1.
    at end.
    append itab1.
      clear itab1.
    endat.
    endloop.
    loop at itab1.
      write / itab1.
    endloop.
    Plzzz Reward if useful,
    Mahi.
    Message was edited by:
            Maheswari Chegu

  • Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).

    Hi,
    I have a file where fields are wrapped with ".
    =========== file sample
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    "asdsa","asdsadasdas","1123"
    ==========
    I am having a .net method to remove the wrap characters and write out a file without wrap characters.
    ======================
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    asdsa,asdsadasdas,1123
    ======================
    the .net code is here.
    ========================================
    public static string RemoveCharacter(string sFileName, char cRemoveChar)
                object objLock = new object();
                //VirtualStream objInputStream = null;
                //VirtualStream objOutStream = null;
                FileStream objInputFile = null, objOutFile = null;
                lock(objLock)
                    try
                        objInputFile = new FileStream(sFileName, FileMode.Open);
                        //objInputStream = new VirtualStream(objInputFile);
                        objOutFile = new FileStream(sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString(), FileMode.Create);
                        //objOutStream = new VirtualStream(objOutFile);
                        int nByteRead;
                        while ((nByteRead = objInputFile.ReadByte()) != -1)
                            if (nByteRead != (int)cRemoveChar)
                                objOutFile.WriteByte((byte)nByteRead);
                    finally
                        objInputFile.Close();
                        objOutFile.Close();
                    return sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString();
    ==================================
    however when I run the bulk load utility I get the error 
    =======================================
    Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).
    ==========================================
    the bulk insert statement is as follows
    =========================================
     BULK INSERT Temp  
     FROM '<file name>' WITH  
      FIELDTERMINATOR = ','  
      , KEEPNULLS  
    ==========================================
    Does anybody know what is happening and what needs to be done ?
    PLEASE HELP
    Thanks in advance 
    Vikram

    To load that file with BULK INSERT, use this format file:
    9.0
    4
    1 SQLCHAR 0 0 "\""      0 ""    ""
    2 SQLCHAR 0 0 "\",\""   1 col1  Latin1_General_CI_AS
    3 SQLCHAR 0 0 "\",\""   2 col2  Latin1_General_CI_AS
    4 SQLCHAR 0 0 "\"\r\n"  3 col3  Latin1_General_CI_AS
    Note that the format file defines four fields while the fileonly seems to have three. The format file defines an empty field before the first quote.
    Or, since you already have a .NET program, use a stored procedure with table-valued parameter instead. I have an example of how to do this here:
    http://www.sommarskog.se/arrays-in-sql-2008.html
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Rows to columns question

    Hi all,
    10.2.0.3 database.
    I need to convert MONTH ROW into columns. I tried few things with SYS_CONNECT_BY_PATH without any luck.
    Example:
    HOST     DB     TS     MONTH     SIZE_MB
    =========== === ====== ======= =======
    cltcrmspdb01     NP5     AIMD01     2005-08     4198
    cltcrmspdb01     NP5     AIMD01     2005-12     4627
    cltcrmspdb01     NP5     AIMD01     2005-05     2414
    cltcrmspdb01     NP5     AIMD01     2005-06     3966
    cltcrmspdb01     NP5     AIMD01     2006-04     5215
    cltcrmspdb01     NP5     AIMD01     2006-07     6288
    cltcrmspdb01     NP5     AIMD01     2006-05     5903
    cltcrmspdb01     NP5     AIMD01     2005-07     3977
    cltcrmspdb01     NP5     AIMD01     2006-06     6004
    cltcrmspdb01     NP5     AIMD01     2006-08     6312
    cltcrmspdb01     NP5     AIMD01     2005-11     4298
    cltcrmspdb01     NP5     AIMD01     2006-02     4591
    cltcrmspdb01     NP5     AIMD01     2005-09     3956
    cltcrmspdb01     NP5     AIMD01     2006-10     971
    cltcrmspdb01     NP5     AIMD01     2005-10     3850
    cltcrmspdb01     NP5     AIMD01     2006-01     4835
    cltcrmspdb01     NP5     AIMD01     2006-03     5429
    cltcrmspdb01     NP5     AIMD01     2006-09     6312
    HOST DB TS 2005-08 2005-09 2005-10 ...... 2006-09
    ============ === ====== ======= ======= ======= =======
    cltcrmspdb01 NP5 AIMD01 4198 4627 2414 6312
    Can somebody help me here. thanks in advance

    You need pivot query like this, (I didn't list all the months)
    select HOST, DB, TS,
               max( decode( month, '2005-08', SIZE, null ) ) 2005_08,
               max( decode( month, '2005-09', SIZE, null ) ) 2005_09,
               max( decode( month, '2005-10', SIZE, null ) ) 2005_10,
               max( decode( month, '2005-11', SIZE, null ) ) 2005_11
          from ( select HOST, DB, TS, MONTH, sum(SIZE_MB) SIZE
                   from yourtable
                  group by  HOST, DB, TS, MONTH)
         group by HOST, DB, TS

  • Converting from rows to columns

    Converting Rows to Columns
    We have one business requirment where they want to convert rows to columns. The data we are talking about is 2-3 TB of data. Data looks something in this format.
    Table Structure
    Date_1 Unit_Number Data_ID Data_Value
    2013-01-02 00:00:00 100013 123 671
    2013-01-02 00:00:00 100014 131 771
    2013-01-02 00:00:00 100015 281 812
    2013-01-02 00:00:00 100016 712 979
    2013-01-02 00:00:00 100017 715 719
    Pivoted table
    Date_1 RY XY HJ KD IK GH HH KK TK RT ...
    2013-01-02 00:00:00 671 771 812 979 719 979 719 980 799 79
    2013-01-02 00:10:00 671 771 812 979 719 979 719 980 799 79
    and so on
    We are pivoting this data using query and creating view using query something like below
    select a.date_1 date_1 a.unit_number system_number,
    max(CASE WHEN a.data_id= 123 then a.DATA_Value END) RY,
    max(CASE WHEN a.data_id= 281 then a.DATA_Value END) XY,
    max(CASE WHEN a.data_id=712 then a.DATA_Value END) HJ,
    max(CASE WHEN a.data_id=715 then a.DATA_Value END) KD,
    max(CASE WHEN a.data_id=666 then a.DATA_Value END) IK,
    max(CASE WHEN a.data_id=231 then a.DATA_Value END) GH,
    max(CASE WHEN a.data_id=881 then a.DATA_Value END) HH,
    max(CASE WHEN a.data_id=734 then a.DATA_Value END) KK,
    max(CASE WHEN a.data_id=734 then a.DATA_Value END) TK,
    max(CASE WHEN a.data_id=724 then a.DATA_Value END) TK,
    from FROM table_name group by 1,2
    We also tried pivot clause but still no major improvement in performance.
    There are about 40 such rows that we are trying to convert into columns. We created indexes, Primary, Secondary and referencial ones to tune this overall query. Also added paritions, We find this conversion works fine for smaller query, however for larger set of data we get high CPU and IO and also often runs into spool error. The data set we are runing on this query are about 3-4 TB. There is another table where we have about 100 rows which we need to convert into one row and again size goes to 4-5 TB
    Questions I have
    1) Is there better way to convert columns to Rows?
    2) What options can be use to reduce CPU, IO and Spool error?
    3) Does Orage 11g datawarehouse any feature which will hellp us here
    4) Any other appproach or design suggested here that will help us?
    This design is pushed by our business due to flexibility this design offers and we are runing into performance and we are trying to make this work without impacting CPU, Spool and IO
    Any suggestions would help us here, thanks for reading this

    Hi,
    Here's one way to do that:
    WITH     got_times     AS
         SELECT     MAX ( CASE
                   WHEN  msg_line = 'LONGITUDINAL REFRESH HAS BEGUN'
                   THEN  msg_datetime
                  )          AS start_time
         ,     MAX ( CASE
                   WHEN  msg_line = 'LONGITUDINAL REFRESH HAS COMPLETED'
                   THEN  msg_datetime
                  )          AS end_time
         FROM     xxwv.xxwv_hsum_info_reports
    SELECT     start_time
    ,     end_time
    ,     (end_time - start_time) * 24 * 60     AS duration_minutes
    FROM     got_times
    ;When you run the two different (but very similar) to get the two times, you have two different WHERE clauses. You can combine those two similar queries into one, but whatever WHERE clause you have will apply to the whole query. Whenever you wish you could apply a WHERE clause just to one column, think of CASE instead.

  • Hi, how can i break the value for a row and column once i have converted the image to the array?????​??

    Hi, I would like to know how can i break the value for a row and column once i have converted the image to the array. I wanted to make some modification on the element of the array at a certain position. how can i do that?
    At the moment (as per attachhment), the value of the new row and column will be inserted by the user. But now, I want to do some coding that will automatically insert the new value of the row and the column ( I will use the formula node for the programming). But the question now, I don't know how to split the row and the column. Is it the value of i in the 'for loop'? I've  tried to link the 'i' to the input of the 'replace subset array icon' , but i'm unable to do it as i got some error.
    Please help me!
    For your information, I'm using LABView 7.0.

    Hi,
    Thanks for your reply.Sorry for the confusion.
    I manage to change the array element by changing the row and column value. But, what i want is to allow the program to change the array element at a specified row and column value, where the new value is generated automatically by the program.
    Atatched is the diagram. I've detailed out the program . you may refer to the comments in the formula node. There are 2 arrays going into the loop. If a >3, then the program will switch to b, where if b =0, then the program will check on the value of the next element which is in the same row with b but in the next column. But if b =45, another set of checking will be done at a dufferent value of row and column.
    I hope that I have made the problem clear. Sorry if it is still confusing.
    Hope you can help me. Thank you!!!!
    Attachments:
    arrayrowncolumn2.JPG ‏64 KB

  • Row to Column in 10g

    Hello All,
    I have a requirement where I have to convert rows to columns and vice versa in 10g.
    Pivot isn't supported in 10g.
    Actual query looks like this
    change_name    primary_key_id
    ASSET              1501 
    COLLATERAL         1501
    ASSET              1502
    COLLATERAL         1510
    ASSET              1503
    COLLATERAL         1515
    Required Output:
    change_table_name  Asset      Collateral
    Primary_key_id         1501       1501
    Primary_key_id2        1502     
    Primary_key_id3                     1510
    Primary_key_id4        1503     
    Primary_key_id5                     1515Thx
    Shank.
    Edited by: SamFisher on May 16, 2012 7:48 PM

    Hi,
    SamFisher wrote:
    Hello All,
    I have a requirement where I have to convert rows to columns and vice versa in 10g.
    Pivot isn't supported in 10g.Pivot can be done in any version of Oracle.
    The PIVOT keyword of the SELECT command isn't supported in Oracle 10. That's only one way of pivoting.
    Actual query looks like this
    change_name    primary_key_id
    ASSET              1501 
    COLLATERAL         1501
    ASSET              1502
    COLLATERAL         1510
    ASSET              1503
    COLLATERAL         1515
    Required Output:
    change_table_name  Asset      Collateral
    Primary_key_id         1501       1501
    Primary_key_id2        1502     
    Primary_key_id3                     1510
    Primary_key_id4        1503     
    Primary_key_id5                     1515
    I think you want something like this:
    SELECT     'Primary_key_id
         || TO_CHAR ( NULLIF  ( ROW_NUMBER () OVER (ORDER BY  NVL ( a.primary_key_id
                                             , c.primary_key_id
                      , 1
               )          AS change_table_name
    ,     a.primary_key_id     AS asset
    ,     c.primary_key_id     AS collateral
    FROM          table_x      a
    FULL OUTER JOIN     table_x  c  ON  a.primary_key_id  = c.primary_key_id
    -- Next 4 lines added after Ankit, below
                       AND     a.change_name     = 'ASSET'
                       AND     c.change_name     = 'COLLATERAL'
    WHERE     a.change_name     = 'ASSET'
    OR     c.change_name     = 'COLLATERAL'
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
    This generates a unique change_table_name for each row. I don't see how you get the values you said you wanted associated with the other columns. That is, I have the same question as Justin:
    Justin Cave wrote:
    ... How do you know that 1502 goes with primary_key_id2 and not primary_key_id3 or 4 or 1?Perhaps you don't really care which change_table_name is given to each row, just so long as they are unique, and numbered with consecutive integers (except for 1). If you really do need exactly what you posted, explain how you get it. You probably just need to change the analytic ORDER BY clause.
    Edited by: Frank Kulash on May 17, 2012 6:56 AM
    Corrected query

Maybe you are looking for

  • 64 bit Photoshop CS 5.1 Extended crashes every time I create a new file or open an existing file

    I installed the 64 bit version of Photoshop CS 5.1 Extended successfully.  It opens fully without issue.  However, any time I create a new file or open an existing file, it crashes.  I figured this would have something to do with my graphics card, bu

  • Clips not displaying in timeline

    I've been having a nightmare of a time editing a project because my clips are randomly not displaying in my sequence timeline.  The project recognizes them as being there and will play them when I preview, but some clips aren't represented graphicall

  • Problem of setuping a source system in bi 7.0

    Dear All,   I'm now using BI 7.0, and when I wants to setup a souce system in the folder SAP, I found a problem. The system appears in BI folder with a strange icon. I don't know why, can anybody explain it and give a solution?   Thanks a lot.

  • Dreamweaver CS4 wont load

    Dreamweaver CS4 wont load - I get a runtime error with the following message. The application has requested the runtime to terminate in an unusual way. I am running Windows 7. This error came out of the blue. Does anyone have any suggestions on how t

  • Audio Compatibility with iHome

    Hey everyone, You all have been so helpful in the past, so I'm coming to all you Apple support forum gurus for two very puzzling audio questions: 1) I have an iHome Bluetooth/Alarm Clock (see here: http://www.ihomeaudio.com/products.asp?productid=104