Switch row into a column in the view

EMP TABLE
empid pay_type_id      pay_factor
101      A           10
111      A           15
112      B           3000
101      C           250
111      C           250
PAY_TYPES table
pay_type_id      pay_type_code description
A           var           variable pay
B           com           commission
C           car           car allowance
D           bon           bonus
View I would like to create should display like below. there cab be many pay-type-codes and these should not be hardcoded!
empid      var      com      car      bon
101      10      null      250      null
111      15      null      250      null
112      null      3000 null      null
basically I want to switch 'pay_type_id's as a column in the view

Hi,
Use Dynamic SQL.
For example:
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
     a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus. 
(This can be easily adapted to PL/SQL or other tools.)
NOTE: Using SQL*Plus file I/O, as in this example, is just
one of many ways to do dynamic SQL.
PROMPT     ==========  0. Basic Pivot  ==========
SELECT     deptno
,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
FROM     scott.emp
WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY     deptno
ORDER BY     deptno
PROMPT     ==========  1. Dynamic Pivot  ==========
--     *****  Start of dynamic_pivot.sql  *****
-- Suppress SQL*Plus features that interfere with raw output
SET     FEEDBACK     OFF
SET     PAGESIZE     0
SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT     DISTINCT
     ',     COUNT (CASE WHEN job = '''
||     job
||     ''' '     AS txt1
,     'THEN 1 END)     AS '
||     job
||     '_CNT'     AS txt2
FROM     scott.emp
ORDER BY     txt1;
SPOOL     OFF
-- Restore SQL*Plus features suppressed earlier
SET     FEEDBACK     ON
SET     PAGESIZE     50
SPOOL     p:\sql\cookbook\dynamic_pivot.lst
SELECT     deptno
@@dynamic_pivot_subscript
FROM     scott.emp
GROUP BY     deptno
ORDER BY     deptno
SPOOL     OFF
--     *****  End of dynamic_pivot.sql  *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one.  If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one.  That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
*/By pure chance, I still had this script in my paste buffer from ansering [another thread|http://forums.oracle.com/forums/thread.jspa?threadID=1013260&tstart=0].

Similar Messages

  • How to convert a row into a column with the row headers displayed as column in javaFx?

    How do in convert a row of data into column of data to display as shown below:
    Column1|Column2|Column3|Column4
    C1          | C2          | C3           |  C4
    C5          | C6          | C7           |  C8
    How to convert the above default behavior to as below
    Column1| C1 | C5
    Column2| C2 | C6
    Column3| C3 | C7
    Column4| C4 | C8

    .

  • 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 Transpose a Row into a Column ? (URGENT)

    I am trying to transpose a row into a column and please pay attention "Just one row of a table into a column of another table". Unlike Excel, in Numbers there is no easy way to transpose data but this is a bit urgent to me, any help would be appreciated!!!!

    Dear Friend,
    I have been looking for an answer the whole day and have performed every possible solution in the index, transpose, lookup and all the other recommended functions, none of them have worked for me in this case. I have gone through more than 20 posts on the discussion board but all of them were useless. I havent tried your method yet but although I appreciate your help and time, I dont remember forcing you or anyone else to help me, I just looked at posting my question  as an option to avoid writing long scripts for such a basic function that is easily available on excel under the special paste option.
    I thank you very much in advance for the advice.
    PS. I tried it and with a couple of modifications it worked, thank you very much for making my day
    Message was edited by: cool3pehr

  • Adding Specific columns of dynamic internal table row into another column

    Hi Gurus,
    I need to add  few columns of a dynamic internal table row into another column:
    Article description hy01 hy02 total
    101      panza         10     12      22
    102      masht         12     12     24
    dynamic internal table is created and columns hy01 hy02.... can increase
    How to add the the values in hy01 hy 02... into total.
    Regards,
    Dep

    Hi,
    If you really want to have a dynamic table, then you will have to find a way to generate a whole new table, and then copy the data from the old table to the new one. There is no way to modify a type during runtime in ABAP.
    Here an example how to generate a dynamic table based on another internal table, hope this will help you.
    TYPE-POOLS: slis.
    PARAMETERS: p_nb_hy TYPE i DEFAULT 2. "Number of new HY columns to be added
    * Type ZST_T:
    *   matnr  TYPE matnr
    *   maktx  TYPE maktx
    *   hy01   TYPE i
    *   total  TYPE i
    TYPES: ty_t TYPE STANDARD TABLE OF zst_s.
    PERFORM main.
    *&      Form  main
    *       text
    FORM main.
      DATA: lt_fieldcat     TYPE slis_t_fieldcat_alv,
            lt_t            TYPE ty_t,
            lr_new_t        TYPE REF TO data.
      FIELD-SYMBOLS: <lt_new_t> TYPE STANDARD TABLE.
      "Add some lines to LT_T just to have something to display on screen
      DO 10 TIMES.
        APPEND INITIAL LINE TO lt_t.
      ENDDO.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'ZST_S'
        CHANGING
          ct_fieldcat      = lt_fieldcat.
      "Copy LT_T to LR_NEW_T
      PERFORM extend_and_copy_table USING lt_t p_nb_hy CHANGING lr_new_t lt_fieldcat.
      CLEAR lt_t. "Not needed anymore...
      ASSIGN lr_new_t->* TO <lt_new_t>.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = lt_fieldcat
        TABLES
          t_outtab    = <lt_new_t>.
    ENDFORM.                    "main
    *&      Form  extend_and_copy_table
    FORM extend_and_copy_table USING ut_t           TYPE STANDARD TABLE
                                     uv_nb_hy       TYPE i
                               CHANGING cr_t        TYPE REF TO data
                                        ct_fieldcat TYPE slis_t_fieldcat_alv
                               RAISING cx_sy_struct_creation cx_sy_table_creation.
      DATA: lo_tabledescr      TYPE REF TO cl_abap_tabledescr,
            lo_structdescr     TYPE REF TO cl_abap_structdescr,
            lo_new_structdescr TYPE REF TO cl_abap_structdescr,
            lo_new_tabledescr  TYPE REF TO cl_abap_tabledescr,
            lt_components      TYPE cl_abap_structdescr=>component_table,
            ls_component       TYPE cl_abap_structdescr=>component,
            lv_field_cnt       TYPE numc2,
            ls_fieldcat        TYPE slis_fieldcat_alv,
            lr_fieldcat        TYPE REF TO slis_fieldcat_alv.
      FIELD-SYMBOLS: <ls_old_s> TYPE ANY,
                     <lt_new_t> TYPE STANDARD TABLE,
                     <ls_new_s> TYPE ANY.
      "Get the list of all components from UT_T line structure
      lo_tabledescr  ?= cl_abap_tabledescr=>describe_by_data( ut_t ).
      lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
      lt_components  = lo_structdescr->get_components( ).
      "The new columns will be from type of column HY01
      ls_component-type = lo_structdescr->get_component_type( 'HY01' ).
      "The new columns will have the same fieldcat info as column HY01
      READ TABLE ct_fieldcat INTO ls_fieldcat WITH KEY fieldname = 'HY01'.
      "HY<lv_field_cnt> = new field name
      lv_field_cnt = uv_nb_hy + 1.
      "For each new column...
      DO uv_nb_hy TIMES.
        "Generate the new column field name
        CONCATENATE  'HY' lv_field_cnt INTO ls_component-name.
        ls_fieldcat-fieldname = ls_component-name.
        "Add the new field to the components of the new structure
        INSERT ls_component INTO lt_components INDEX 4.
        "Add the new field's fieldcat info to the fieldcat
        INSERT ls_fieldcat  INTO ct_fieldcat   INDEX 4.
        lv_field_cnt = lv_field_cnt - 1.
      ENDDO.
      "Adjust the COL_POS from fieldcat
      LOOP AT ct_fieldcat REFERENCE INTO lr_fieldcat.
        lr_fieldcat->col_pos = sy-tabix.
      ENDLOOP.
      "Create the new table
      lo_new_structdescr = cl_abap_structdescr=>create( p_components = lt_components ).
      lo_new_tabledescr  = cl_abap_tabledescr=>create( p_line_type = lo_new_structdescr ).
      CREATE DATA cr_t TYPE HANDLE lo_new_tabledescr.
      ASSIGN cr_t->* TO <lt_new_t>.
      "Copy all data from old to new table
      LOOP AT ut_t ASSIGNING <ls_old_s>.
        APPEND INITIAL LINE TO <lt_new_t> ASSIGNING <ls_new_s>.
        MOVE-CORRESPONDING <ls_old_s> TO <ls_new_s>.
      ENDLOOP.
    ENDFORM.                    "main

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

  • Changing rows into different column names

    Hi,
    i need to tranpose the rows into differnent column names
    my sample data :
    id , val
    1 3
    1 4
    1 5
    into
    id , val1, val2 , val3 , val4 ... valn ..
    1 3 4 5
    from askTom's i see that it's tranpose into a single column using the ref cursor ?
    how can i do made it into different column names ?
    kindly advise
    tks & rdgs

    For example, lets say that you want to order your columns from least value to greatest and that you'll never have more than three values per id. Then you can use the analytic function row_number() like this to create a pivot value.
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table;And so your pivot query ends up looking like this.
    select id,
           max(case when rn=1 then val end) AS val1,
           max(case when rn=2 then val end) AS val2,
           max(case when rn=3 then val end) AS val3
      from (
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table
    group by id;But notice that I started out by making up answers to Justin's questions. You'll have to supply the real answers.

  • Inserting multiple selection from checkbox into one column of the database

    Hi,
    How to insert multiple selection values from checkbox into one column of the database.
    Anyone can u help me
    Thanx

    hi
    try to use request.getParameterValues("fieldname")

  • How to transpose rows into multiple columns using pivot table

    I have 1 row containing 12 columns with value "JAN", "FEB", "MAR", "J-1","F-1","M-1","J-2","F-2","M-2","J-3","F-3","M-3"
    I want to display as
    JAN J-1 F-1 M-1
    FEB J-2 F-2 M-2
    MAR J-3 F-3 M-3
    How do I achieve the above?

    Today you have only 3 months JAN, FEB, MAR. Is it always the same number of columns. What if there are more months added to this row?
    Is your data really coming from relational source or some sort of text file?
    There is a better way to do this in narrative view using HTML if your requirement is just to show them in multiple rows and do some calculations.
    Go to Narrative View;
    In prefix, use <html> <table>
    In 'Narrative' text box add something like this
    <tr> <td> @1 </td> <td> @4 </td> <td> @7 </td> </tr>
    <tr> <td> @2 </td> <td> @5 </td> <td> @8 </td> </tr>
    <tr> <td> @3 </td> <td> @6 </td> <td> @9 </td> </tr>
    In Suffix, use </table> </html>
    You can also add simple calculations like sum etc at the very bottom of these rows as grand totals.
    kris

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

  • Convert Rows  into single column

    Hi,
    My employee details table has data like below,
    employee_id position department
    100 technician 50
    100 IT 80
    101 Accountant 60
    101 Accounting Manager 70
    Now i want to covert the rows into column. So my output should be like this.
    output:
    employee_id position department position1 department1
    100 technician 50 IT 80
    101 Accountant 60 Accounting Manager 70
    Help me on this
    Edited by: Vi on Mar 22, 2012 5:36 AM
    Edited by: Vi on Mar 22, 2012 5:36 AM

    Igor.M wrote:
    http:// website link removed /t_converting_rows_columns.htm
    Please don't post links to commercial websites that are only trying to sell their products and services. It breaches the terms of use of the forums.
    There are usually more suitable websites giving much more valuable information without all the self promotion (google adwords etc. are acceptable), or in the case of this particular question there is a FAQ post that relates to it...
    {message:id=9360005}

  • Transform Result-Rows into Result-Columns

    Hello,
    I'm looking for a method to display part of the result of a query not in rows but intstead into columns.
    What do I have are two tables (object and parts) and each object can have 1 or 10 or probably 50 parts. When I do the following
    select o.sysob, o.number, o.name, p.number form part p, object o where p.sysob = o.sysob
    I get all information in rows underneath. What I'm looking for is a way to get all the p.number results into columns beside the object information in one row for each object.
    Hopefully someone has got a clue what I need.
    Thanks
    Carsten

    first problem: I'm using Oracle 9i and 10g, so PIVOT
    is not availableTrue, the PIVOT functionality is only available from 11g but, if you had searched correctly, you would have found plenty of examples of how to pivot data using 9i and 10g.
    second problem: crosstable with an unknown number of
    results to bring into columns doesn't make it as easy
    as in the examples shown.So you are saying that you will have a dynamic number of columns in the result set? The only way I know to achieve this is shown here:
    How to pipeline a function with a dynamic number of columns?

  • Problem with binding value on the UI  from a calculated column in the view

    I have calculated field "Readiness" in my db view, which gets calculated based on other columns in the same table. I have added new column to my EO using "Add from table" option and added the same column from to VO using "Add from EO" option. In my application, I will update a particular date field in the UI and this calculated column "Readiness" in the db will be set to yes or no and this logic is working fine, both date date field and calculated field are in same view object. I have added a attribute binding to this "Readiness" column in my view page. The problem is the calculated column value does not reflect the new value in the db, it shows the old value. I have tried different refresh option for the iterator and ppr option for the field binding. Even after reloading the page, the value shown on the UI page is different from the value in db, other bindings on the UI page works fine, not sure any special settings are required for the Calculated columns. any ideas are appreciated.
    Thanks for your help,
    Surya

    I tried to add soms debugging statements in the EO and getters method, the calcaulated column is not picking the value in db view. I'm not any special iterator/field settings are required at BC level. I'm a newbie, any help is appreciated.
    Thanks,
    Surya

  • Numbers Export to Excel adds 1 Row and 1 Column to the Freeze Header/Columns.

    Exporting a Numbers file to Excel, that has 1 Freeze Column and 5 Freeze Headers, somehow adds an additional Row & Column when opened in Excel.
    Thoughts?

    I found the answer to this question with help from SAP Support.
    In the Cross-Tab Expert, Customize Style tab, click "_Column Totals on Top_".
    Then, the Excel Data Only report will show the row titles Top-aligned for the row group.

  • One Row into multiple Column

    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    I am trying to get output following format
    ID_1    ID_2   ID_3  ID_4
    100     200    300   400
    1000    1200   1300  1400
    Each row in EmpId column will have only max. four values
    Thanks
    V

    One more method:
    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    select * from #ids
    ;WITH
    L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
    L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
    L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
    L3 AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
    Numbers AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM L3)
    SELECT [1] AS Column1, [2] AS Column2, [3] AS Column3, [4] AS Column4
    FROM
    (SELECT rn,
    ROW_NUMBER() OVER (PARTITION by rn ORDER BY nums.n) AS PositionInList,
    LTRIM(RTRIM(SUBSTRING(valueTable.empid, nums.n,
    charindex(N',', valueTable.empid + N',', nums.n) - nums.n))) AS [Value]
    FROM Numbers AS nums INNER JOIN (Select row_number()over (Order by (Select NULL)) rn , Empid From #ids) AS valueTable ON nums.n <= CONVERT(int, LEN(valueTable.empid))
    AND SUBSTRING(N',' + valueTable.empid, n, 1) = N',') AS SourceTable
    PIVOT
    MAX([VALUE]) FOR PositionInList IN ([1], [2], [3], [4])
    ) AS Table2
    drop table #ids

Maybe you are looking for

  • Another Error in Initializing Database in SQL Server 2008 R2

    Hi All, I'm facing very strange problem with my current LiveCecle ES 2.5 deployed in the Windows Server 2008 in which i must use Websphere 6.1 as the Application server and then then Databse must be using SQL Server 2008 R2. see the following error m

  • [Solved] Problem with xf86-video-intel after upgrade to xorg 1.16

    Hi everyone, since the upgrade to xorg-server 1.16 i can't get X to work again on my thinkpad R50e with an old intel integrated chip (Intel Extreme Graphics 2). I first encountered the error "cannot open /dev/tty0": http://okraits.de/upload/xorg/Xorg

  • Out on Safari and not going well

    Hello All, I wonder if you can help me. I am using Safari on Windows to view my Mobile Me calendars. However when I go to print the calendar all I get is a blank page. Is there anything I can do to print out the calendar? Cheers nick

  • Has anyone every had a green screen on their ipad?

    I just went to put on my Ipad and the screen is tinted green all over it! Just wondering if anyone has ever had this before?

  • Error 4701 Burning Issues

    Well... I have a strange one. I'm able to burn some playlists, but not others. I purchased and downloaded an album yesterday - attempted to burn. Error: 4701 Thought I'd try another playlist/album. No problem. Successful burn. Any thoughts? I've down