Column to row conversion
I would like to convert rows to columns of a sql.
select col1, col2, col3, col4
ABC 1 2 3
DEF 4 5 6
GHI 7 8 9
I want to convert to
ABC DEF GHI
1 4 7
2 5 8
3 6 9
Thanks for your response.
select regexp_substr( col1,'[^\,]+',1,1) column1,
regexp_substr( col1,'[^\,]+',1,2) column2,
regexp_substr( col1,'[^\,]+',1,3) column3
from (
WITH t AS
(select 'ABC' col1, 1 col2, 2 col3, 3 col4 from dual union
select 'DEF', 4, 5, 6 from dual union
select 'GHI', 7, 8, 9 from dual
SELECT substr(SYS_CONNECT_BY_PATH (col1, ' ,'),2) col1
FROM (SELECT col1,
ROW_NUMBER () OVER ( ORDER BY COl1) rn
FROM t)
WHERE connect_by_isleaf = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
union all
SELECT substr(SYS_CONNECT_BY_PATH (col2, ' ,'),2) col2
FROM (SELECT col2,
ROW_NUMBER () OVER ( ORDER BY COl2) rn
FROM t)
WHERE connect_by_isleaf = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
union all
SELECT substr(SYS_CONNECT_BY_PATH (col3, ' ,'),2) col3
FROM (SELECT col3,
ROW_NUMBER () OVER ( ORDER BY COl3) rn
FROM t)
WHERE connect_by_isleaf = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
union all
SELECT substr(SYS_CONNECT_BY_PATH (col4, ' ,'),2) col4
FROM (SELECT col4,
ROW_NUMBER () OVER ( ORDER BY COl4) rn
FROM t)
WHERE connect_by_isleaf = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
) t1
Similar Messages
-
Column to row conversion using script
Hello,
I am in need of a script to convert a file having 1 column to rows.
e.g
File is having entries like below
1
2
3
4
5
And I want to convert them like below.
1 2 3 4 5
Can any body help me on this ?
Thank you
Regards,
~AnoopPlease show what you type.
I test my example.
For 10st post
#!/bash - This line must present
For my example - attantion - first comannd printf
You result look like you type print
Regards.
Edited by: Nik on 28.06.2011 11:44 -
Dynamic internal table- column to row conversion
Hello all,
Inside a program i generate a dynamic internal table and
This table has one single column. But I need to convert the rows as columns.
Eg:
dynamic internal table ITAB has content
Forbes
Times
Reuters
Warner
stern
I would like to have a ITAB2 like this
Forbes Times Reuters Warner Stern
Please note this is a Dynamic internal table!!!!
I need some approach for my problem. Thanks a lot in advance.
Karthik.Hi karthik,
1.
For this purpose,
in my program,
<b> there is an INDEPENDENT FORM</b>
whose inputs are
<b> LIST OF FIELDS, (just as u require)</b>
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying list of fields.
4.
REPORT abc.
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
field list
ddfields-fieldname = 'BUKRS'.
APPEND DDFIELDS.
ddfields-fieldname = 'MATNR'.
APPEND DDFIELDS.
PERFORM mydyntable .
see <DYNTABLE> in debug mode.
BREAK-POINT.
INDEPENDENT FORM
FORM mydyntable .
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
data : lt TYPE lvc_t_fcat .
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m. -
Need help on Unpivot (Columns to rows conversion)
Could you please help me to do unpivot using sql?
Table creation and insertion scripts:
create table REQ
ID NUMBER,
VALUE VARCHAR2(20)
insert into REQ (ID, VALUE)
values (1, 'HI,HELLO, KARTHI');
insert into REQ (ID, VALUE)
values (2, 'ARE,YOU,FINE,BHAR');
insert into REQ (ID, VALUE)
values (3, '100,200,300');
commit;
I need to view the data in the below format
ID VALUE
1 HI
1 HELLO
1 KARTHI
2 ARE
2 YOU
2 FINE
2 BHAR
3 100
3 200
3 300However, I would take care on the performance issue.So let's use the model clause:
SQL> set autotrace on
SQL> select id
2 , v
3 from req
4 model
5 partition by (id)
6 dimension by (0 i)
7 measures (value v)
8 rules iterate (10) until (instr(v[iteration_number+1],',') = 0)
9 ( v[iteration_number+1] = substr(v[iteration_number],instr(v[iteration_number],',')+1)
10 , v[iteration_number] = substr(v[iteration_number],1,instr(v[iteration_number],',')-1)
11 )
12 order by id
13 , i
14 /
ID V
1 HI
1 HELLO
1 KARTHI
2 ARE
2 YOU
2 FINE
2 BHAR
3 100
3 200
3 300
10 rijen zijn geselecteerd.
Uitvoeringspan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=3 Bytes=75)
1 0 SORT (ORDER BY) (Cost=3 Card=3 Bytes=75)
2 1 SQL MODEL (ORDERED FAST) (Cost=3 Card=3 Bytes=75)
3 2 TABLE ACCESS (FULL) OF 'REQ' (TABLE) (Cost=2 Card=3 By
tes=75)
Statistics
48 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
271 bytes received via SQL*Net from client
6 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processedRegards,
Rob. -
Need some help to display the output data in the below format,Pls help out...
Eg:
OV:Old Value
NV:New Value
ID OV NV
1 -- 100
1 100 200
1 200 300
OUTPUT:
ID VALUES
1 100 200 300Hi,
i think this link helpful to you
http://www.club-oracle.com/forums/unpivoting-column-to-row-conversion-techniques-sql-t145/ -
Populate columns with row values in Sql Server Reporting Services
I have got a dataset with 2 columns named Row and Title. There are 8 rows in this dataset and I want to display those 8 titles within columns in a table. So I create a table with 8 columns and set each column's expression to
=LookUp(Fields!Row.Value,1,Fields!Title.Value,"Titles")
=LookUp(Fields!Row.Value,2,Fields!Title.Value,"Titles")
=LookUp(Fields!Row.Value,3,Fields!Title.Value,"Titles")
However only the first column displays a title. The other 7 display nothing. Is my expression wrong?Hi,
Is the row datatype non-numeric? Maybe the lookup is failing for that reason. You coulr try adding a conversion to the field:
=LookUp(cint(Fields!Row.Value),1,Fields!Title.Value,"Titles")
Could you, perhaps, instead use a tablix table and put the Title column on the row group? That would pivot the data the way that you want it.
Mark -
How do I lock columns and rows in numbers?
I have a large spreadsheet and I want to scroll up, down, left and right without the need to go up and down to find the name of the column or row where the information goes into.
In Excel you lock a column or row just as easy but in numbers I have looked everywhere and don´t find an answer to this (otherwise) simple procedure.
Thanks tho anyone who can help me.Hi Laura,
The commands you are looking for are "Freeze Header Rows" and "Freeze Header Columns", both found in the Table menu.
To use them, you must first convert the rows and columns you want to keep visible as Header Rows and Header Columns. You can define up to five of each. Rows must be at the top of the table and columns at the left, and multiple header rows/columns must be contiguous.
Be aware that the conversion is not (easily) reversable, and that multiple headers (and footer rows) tend to slow large tables significantly.
To convert an eligible row, hover the mouse over the row reference tab, then click the triangle when it appears. If the row is eligible for conversion (ie. if it is the top non-header row on the table, and is in the top five rows), you will see the option to "Convert to Header Row, seen below for row 2:.
Regards,
Barry -
Interactive Report - Icon View - Dynamic Columns per Rows ?
Hi all,
We use the icon view functionnality in Interactive Report.
Is there a way to display the 'columns per row' attribute as an application item and set it dynamical via PL/SQL ?
Any suggestions?
Thanks in advance for advices,
Regards,
GrégoryHi,
Apex 4.0 interactive reports and images (Scott's thread)
Have some useful information and pointers to the solution you are looking for.
I hope this help.
Thank you,
Ranish -
SWAP COLUMNS AND ROW IN AN INTERNAL TABLE to display in ALV
Hi ,
I want to swap all the rows in an internal table with the column of the internal table to display it horizontally in ALV grid.
e.g
1 2 3 (field names)
A P X
B Q Y
C R Z
should look like :
D A B C
E P Q R
F X Y Z
Where D , E, F in first column is already apended in new table.
Or else is there a way to rotate the ALV grid so that it can display rows as columns & columns as rows.
regardshi,
i have an internal table which is like
f1 f2 f3 f4 (column header)
A 1 2 3
B 4 5 6
C 7 8 9
the values in o/p table should be
A B C ( column header)
1 4 7
2 5 8
3 6 9
Please help!! -
How to enter a data into the specified column and row in a created table
Hi,
I want to enter some data to specified column and row in a already created table. Please let me know how to do this.
Regards
Shivakumar SinghA table is just a 2D array of strings. Keep it in a shift register and use "replace array element" to modify the desired entry programmatically.
If you want to modify it manually and directly from the front panel, make it into a control and type directly into the desired element. (In this case your program would need to write to it using a local variable).
Atttached is a simple example in LabVIEW 7.0 that shows both possibilities.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
ChangeTableEntries.vi 41 KB -
Problem in displaying the data of columns into rows in sap script
hi,
i am working on a sap script and i have to display the dat which is displayed in column into rows but it is not displaying it properly.
eg, C
12.1
Si
5.5
it is displaying the data right now like this but i want to display the data like this:-
eg, C Si
12.1 5.5
plzzprovide me guidelines how to solve this problem.hi,
i am using this code to display the data:-
plzz provide me guidelines where i am getting wrong?
TOPparCOMPONENT DESP,,,,,, INS. LOT #, , , , , , MIC,,,,,,,,,, MIC VALUEparENDTOPparFINAL
PROTECT
IF &I_FINAL-PRUEFLOS& NE '000000000000'
&I_FINAL-MAKTX(23)&&i_final-prueflos(12Z)&
&I_FINAL-kurztext(25)&
&I_FINAL-original_input(8)&
ELSE
&I_FINAL-MAKTX(23)&
&I_FINAL-kurztext(25)&
&I_FINAL-original_input(8)&
ENDIF
ENDPROTECT
ITEMHEAD
POSITION WINDOW
SIZE WIDTH +0 . 4 CH HEIGHT +1 LN
BOX FRAME 10 TW
BOX HEIGHT '1.35' LN INTENSITY 20
IF &PAGE& = '1'
BOX XPOS '0' CH YPOS '0' CM WIDTH '0' CM HEIGHT '43' LN FRAME '10' TW
For horizontal line at top
BOX XPOS '0' CH YPOS '0' CM WIDTH '75' CH HEIGHT '0' LN FRAME '10' TW
COLUMN LINES...
END OF COLUMN LINES...
BOX XPOS '0' CH YPOS '43' LN WIDTH '75' CH HEIGHT '0' LN FRAME '10'TW
BOX XPOS '75' CH YPOS '0' LN WIDTH '0' CH HEIGHT '43' LN FRAME '10'TW
ELSE
COLUMN LINES...
END OF COLUMN LINES...
BOX XPOS '0' CH YPOS '0' CM WIDTH '0' CM HEIGHT '47' LN FRAME '10' TW
BOX XPOS '0' CH YPOS '0' CM WIDTH '75' CH HEIGHT '0' LN FRAME '10' TW
BOX XPOS '0' CH YPOS '0' CM WIDTH '45' CM HEIGHT '0' LN FRAME '10' TW
BOX XPOS '20' CH YPOS '0' CM WIDTH '0' CM HEIGHT '47' LN FRAME '10' TW
BOX XPOS '0' CH YPOS '47' LN WIDTH '75' CH HEIGHT '0' LN FRAME '10'TW
BOX XPOS '75' CH YPOS '0' LN WIDTH '0' CH HEIGHT '47' LN FRAME '10'TW
ENDIF
LINEFEED
NEWPAGE
NEW-PAGE
provide me guidelines to solve this problem.
Edited by: ricx .s on Mar 13, 2009 5:58 AM -
Filling in values based on the column and row headers
I have a question that seems simple, but I can't figure out how to do it and I've searched all over the forum to no avail.
I have one column that is width increasing by 3 in. increments (column A)
I have one row that is height increasing by 3 in. increments (row B)
I have one cell that is price (cell A1)
I have a formula to calculate price per sq. ft.: =CEILING(A3B2/144,1)A1. This gives me the whole sq. ft. number multiplied by the price per sq. ft. to give me a total price at that dimension (A3 is the width, B2 is the height, and A1 is the cell that contains the price per sq. ft.).
*Here is the problem*: When I try to cut and paste or fill the formula to the other cells, it doesn't calculate the formula as =CEILING(column A * Row B/144,1)*A1. Instead, it moves all of the values relative to the new cell that the formula is being pasted or filled to.
Is there a way to autofill the cells so that the formula continues to refer to the width column, the height row, and the price cell?Aha! Apparently I didn't do enough research before I posted and I have since answered my own question. Here's how you do it. Look for "Distinguishing Absolute and Relative Cell References" and you should be able to find what you need. In my case, here is the formula I needed to have to make the copy and paste function do what I needed it to do: =CEILING($A3*B$2/144,1)*$A$. Hope that helps anyone who may have had the same problem I did.
-
How to get the current selected column and row
Hi,
A difficult one, how do i know which column (and row would also be nice) of a JTable is selected?
e.g.
I have a JButton which is called "Edit" when i select a cell in the JTable and click the button "Edit" a new window must be visible as a form where the user can edit the a part of a row.
Then the column which was selected in the JTable must be given (so i need to know current column) and then i want the TextField (the one needed to be edited) be active with requestFocus(). So it would be
pricetextfield.requestFocus();
Problem now is that i have to click every time in the window the JTextField which was selected in the JTable. I have chosen for this way of editing because my application is multi-user and it would be too difficult for me when everybody did editing directly (catch signals, reload data, etc.).
My question is how do I know the current column and the current row in a JTable?I'm not sure what your mean by the "current" row or column, but the following utility methods return
which row and column have focus within the JTable.
public static int getFocusRow(JTable table) {
return table.getSelectionModel().getLeadSelectionIndex();
public static int getFocusColumn(JTable table) {
return table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
} -
Please help to generate the table from column to rows
Hello -
I have one table with more than 100 columns there are 70 column start with HC1.....HC70 (they are not in sequence) and has some value 0 or 1
Table structure:
HICN_ID HC1 HC2 HC4 HC5 HC6.................................HC70
1234A 0 1 1 0 1 1
3456D 1 0 0 1 0 0
Now What i want is like this..
HICN_ID HC
1234A 2
1234A 4
1234A 6
3456D 1
3456D 5
Can you please help me on this
thanks
nickPlease look at the same scenario from the below link.
You can accomplish this by a "pivot" query. Please look at the small testcase that I prepared below:
SQL> desc t1
Name Null? Type
NAME VARCHAR2(10)
YEAR NUMBER(4)
VALUE NUMBER(4)
SQL>
SQL> select * from t1;
NAME YEAR VALUE
john 1991 1000
john 1992 2000
john 1993 3000
jack 1991 1500
jack 1992 1200
jack 1993 1340
mary 1991 1250
mary 1992 2323
mary 1993 8700
9 rows selected.
SQL> -- now, try out the pivot query
SQL> select year,
2 max( decode( name, 'john', value, null ) ) "JOHN",
3 max( decode( name, 'jack', value, null ) ) "JACK",
4 max( decode( name, 'mary', value, null ) ) "MARY"
5 from
6 (
7 select name, year, value
8 from t1
9 )
10 group by year ;
YEAR JOHN JACK MARY
1991 1000 1500 1250
1992 2000 1200 2323
1993 3000 1340 8700
SQL>
Hope that helps.
Source : http://p2p.wrox.com/oracle/11931-sql-query-convert-columns-into-rows.html
Thanks,
Balaji K. -
[CS2/CS3 JS] Inserting columns or rows in tables
Anybody here know how to insert or add column(s)/row(s) in tables in Indesign Javascript? Please help... Thanks...
Hi Joaquin,
you might have to take use of the add()-command:
Add a column before the first column:
myTable.columns.add( LocationOptions.BEFORE, myTable.columns[0] );
Add a row after the last row:
myTable.rows.add( LocationOptions.AFTER, myTable.rows[-1] );
Martin
Maybe you are looking for
-
Not able to view Data Preview of Attribute View,AV and CV
HI, I have created tables and then created the required attribute view, analytic view and calculation view for parent child hierarchy. I'm facing two problems 1. I'm not able to see the "Data Preview" of any of the views. 2. When i'm trying to import
-
Problems with Use Cases for Process Integration
Hi there, I'm reading the "Simple Use Cases for Process Integration" (http://service.sap.com/xi -> Media Library -> Documentation) and try to setup the variants 1 up to 4. As per description I created the Technical and Business Systems in the SLD. Ev
-
Relationship in Business Partner repository.
I need to do a relationship among the BP where each record in Main Table correspond a BP (Person or Organization). The relationship should link the BPs as shown below: Records 1; John 2; Mary 3; ACME In record 1, I need to say that John is married wi
-
Object Builder does not display
I installed SAP Front End on my computer. I need to use program to assess SAP , so I need to use SAP R/3 DCOM Connector. After I do some setting in SAP R/3 DCOM Connector, and when I connect to a destination, I find the connection is OK. But when I
-
Fw CS5 Properties Panel question
Can I control the way the PROPERTIES PANEL titles my internal pages in the pull down LINK menu? The problem is, by default, all my internal pages are named with their extensions capitalized, ex: ".HTML" (please see the attached .png) I can not link