Converting Table columns to rows
I have a table A as seen in the picture and would like to convert it to Table b as seen in image, group is the lowest level. Here I have taken one eg of top levelId there could be multiple top level ids in actual data.
What would be the best approach to do this, using in an SP.
Neil
Try dynamic PIVOT:
http://www.sqlusa.com/bestpractices2005/dynamicpivot/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Similar Messages
-
How to fix skewed table columns and rows after re-import XML
My question is regarding XML Import in InDesign CS3.
I have a XML that has a table of 5 columns and 5 rows, when I import it into InDesign, the table shows up fine with 5 columns and 5 rows. However when I revise my table to have an additional column, and re-import the XML file, the table gets updated, but instead of with an additional column, it gets 'appended' with an additional row instead (InDesign seems to blindly replace each cell from left to right, top to bottom, and ends up with 6 rows instead). The XML file specifies the number of columns and rows (5 and 5 before, 5 and 6 after), why doesn't InDesign recognize it and automatically add a new column when I re-import the file? Is this problem fixed in CS5.5? Is there a script to fix this?
Here is an example of my old XML vs new XML:
Old:
<frame5>
<Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" aid:trows="5" aid:tcols="5">
<Cell aid:table="cell" aid:crows="1" aid:ccols="1"></Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2006</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2005</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2004</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2003</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores at beginning of period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">678</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores opened during the period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">36</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">50</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">59</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">79</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores closed during the period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">13</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">9</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">7</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">4</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Total stores at end of period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">869</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
</Table>
</frame5>
New:
<frame5>
<Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="5" aid:tcols="6">
<Cell aid:table="cell" aid:crows="1" aid:ccols="1"></Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2007</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2006</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2005</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2004</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">2003</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores at beginning of period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">123</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">678</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores opened during the period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">456</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">36</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">50</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">59</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">79</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores closed during the period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">789</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">13</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">9</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">7</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">4</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">Total stores at end of period</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">1368</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">869</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
</Table>
</frame5>What I mean is, right now there is a "workaround" which requires a user to manually add an extra column before re-importing the XML (with an extra column), otherwise the results get skewed. If by providing a script we can simply ask the user to "run" it, it would be a more "acceptable" solution.
Right. So, one solution would be to use Convert Text to Tables. If you find that works for you, then you can script it.
That's why I asked you...
Of course if nothing is required from the user other than simply re-importing, then that would be the best solution.
Well, one could imagine a script that was attached to the re-import command, or to the link update notification, but probably the first step is to get something that works reasonably well without automating it completely. Especially because triggers to run scripts silently can introduce hard-to-debug problems.
Sure we can switch to use "CALS table and see if this works. The question is, why should we need to? In the 2nd XML there is clearly a different "aid:tcols" value, and yet InDesign seems to ignore it and assume the same # of columns? This sounds like an Indesign bug, can someone confirm? Is there any plans to fix this?
Not to be snarky, but do you want it to work or not? There are the tools you have and the tools you wish you had, and you can't really do much with the ones you wish you had. I'm kind of assuming you are looking for a solution today, not a solution in 2013.
Yes, I believe two of us have confirmed this appears to be a bug.
Plans to fix? Well, we can't really tell you. You could try asking Adobe, but that's not easy information to get out. But you can certainly open a support case at http://adobe.com/go/supportportal and ask. It's not like we have special information here...
But you're probably better off filing a bug first, in that same fashion.
But let's assume no one had filed the bug. CS6 is expected in the March/April 2012 timeframe. That means that they're probably just putting the finishing touches on it right now, and it's going to be very difficult to fix things in it now. So then the earliest you'd likely get it fixed in CS6.5/CS7/whatever which presumably comes out by 2Q2013, and that's assuming Adobe decides to fix it...
I also can't find much documentation on how to update my table to a "CALS table", any examples?
Try this thread:
Re: Importing a CALS table into InDesign CS3 -
Convert single column into rows
hi Gurus,
I have one table test colums are id and name.
id number
name varchar2
data is like
id name
1 xy
2 xyy
3 mm
4 pp
Now my requirement is to convert single column id into rows
i,e my output should be of singel rows like :- 1,2,3,4
How to achive this result .
I dont have any idea to do this query.
Please help guys.
Thanks in advance.
VijayWell,
As long as your code doesn't have to run in production, simplest way is:
WM_CONCAT (but it's not documented)
or use XMLAGG, it's simpler than a connect by:
MHO%xe> with t as (
2 select 1 col, 'xy' str from dual union all
3 select 2, 'xyy' from dual union all
4 select 3, 'mm'from dual union all
5 select 4, 'pp' from dual union all
6 select 8, 'pp' from dual union all
7 select 12, 'pp' from dual union all
8 select 40, 'pp' from dual
9 )-- actual query, based on id's generated above:
10 select rtrim(xmlagg(xmlelement(e,col||',')).extract('//text()'),',') col
11 from t;
COL
1,2,3,4,8,12,40
1 rij is geselecteerd. -
Convert table columns to hyperlinks
hi
can anyone plz tell me how to convert a data in a perticular column of a table into a hyperlink
TIAHi,
Go to the table column that you want to make as link to action/url, remove it and in right click and select insert tablecelleditor and select linktoaction ot linktourl.
Regards
Vinod V -
Problems of having a large table (columns and rows).
hi people,
can anyone give a list of problems that i will be facing when i have a large table(columns/rows). My table generate 5 lakhs record in a year and it keeps growing.
if the answers is labourous, pls give the link of the web-site where i can download it.
How to overcome it?
Thanks in advance
Ganapathyhi justin
i understand u problem too.
10 lakhs in Indian money = 1 million in the US.
Iam trying to understand a system where there will be millions of record over a period of years. I felt that i need to address the problems that should be forseen before the system is developed(some thing like a priliminary investigation or feasibility study before taking up the project). So as of now i have no idea of the system, but do know that there will be millions of records. Iam trying to prepare a document that addresses these issues and how we are going to circumvent the issues and arrive at a solution.
Thanks
Ganapathy -
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. -
HOWTO read the table columns (ALL ROWs of Colm)and display in a texteditor
I am trying to fetch details from VC Table to read all rows of a column. But I am able to get only one row of the column.
Can we export or import data of multiple rows of a column to a texteditor ???Hi Sandeep
Thanks for your reply, As I understand , I have sent the element property to multiselect.
But this is only useful when user select manually at runtime on the columns .. but I am at design time I need to pull column's all the rows using Formula, where I can get only single select at present.
How can I do the multiselect using formula.?
thanks in advance -
How can i hide table columns or rows in pages
I can do it in numbers, but how can i hide a column or down in pages?
Slim it down to nothing?
Peter -
Dear all....I need to convert all columns into rows in a table. For example table has following columns:
Emp_Cod........Val1......Val2......Val3
1 a b c
Now I wish that each column should display as a value like:
Emp_Cod........Val1
1 a
1 b
1 c
Now the one way to solve this job is to write a union statement for each column but for this I'll have to write equal number of select statements as there are columns.
What I need that is there anyway to write minimum code for this job, is there any alternate way???SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
2 select*from t unpivot(v for c in(val1,val2,val3));
EMP_CODE C V
1 VAL1 a
1 VAL2 b
1 VAL3 c
SQL> col COLUMN_VALUE for a20
SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
2 select*from t,table(sys.odcivarchar2list(val1,val2,val3));
EMP_CODE V V V COLUMN_VALUE
1 a b c a
1 a b c b
1 a b c c -
How to convert column to row in 10g and calculate the count
876602 wrote:
Hi ,
i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
this is sample of my date ,
MDN Date
5C4CA98EABA3 20111205235240
5C4CA98EABA3 20110925121833
5C4CA98EABB0 20111025103700
5C4CA98EABB0 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653
5C4CA98EABB8 20111126175853i need the result to be ,
MDN Date count
5C4CA98EABA3 20111205235240 ; 20110925121833 2
5C4CA98EABB0 20111025103700 ; 20111124103700 2
5C4CA98EABB5 20111030175717 1
5C4CA98EABB8 20110925142653 ; 20111126175853 2any help please ,
Edited by: 876602 on 15/12/2011 01:33 صSQL> with t as
2 (
3 select '5C4CA98EABA3' MDN ,'20111205235240' Dte from dual
4 union all
5 select '5C4CA98EABA3','20110925121833' from dual
6 union all
7 select '5C4CA98EABB0','20111025103700' from dual
8 union all
9 select '5C4CA98EABB0','20111124103700' from dual
10 union all
11 select '5C4CA98EABB5','20111030175717' from dual
12 union all
13 select '5C4CA98EABB8','20110925142653' from dual
14 union all
15 select '5C4CA98EABB8','20111126175853' from dual
16 )
17 select mdn,ltrim(sys_connect_by_path(dte,';'),';') s,rw as "count"
18 from
19 (
20 select mdn,dte,row_number() over(partition by mdn order by mdn) rw
21 from t
22 )
23 where connect_by_isleaf = 1
24 start with rw = 1
25 connect by prior rw = rw-1
26 and prior mdn = mdn
27 ;
MDN S count
5C4CA98EABA3 20111205235240;20110925121833 2
5C4CA98EABB0 20111025103700;20111124103700 2
5C4CA98EABB5 20111030175717 1
5C4CA98EABB8 20110925142653;20111126175853 2 -
How to convert column to row in 10g
Hi ,
i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
this is sample of my date ,
MDN Date
5C4CA98EABA3 20111205235240
5C4CA98EABA3 20110925121833
5C4CA98EABB0 20111025103700
5C4CA98EABB0 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653
5C4CA98EABB8 20111126175853i need the result to be ,
MDN Date
5C4CA98EABA3 20111205235240 ; 20110925121833
5C4CA98EABB0 20111025103700 ; 20111124103700
5C4CA98EABB5 20111030175717
5C4CA98EABB8 20110925142653 ; 20111126175853any help please ,
Edited by: 876602 on 15/12/2011 01:33 صNote the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated {forum:id=75} forum.
Regards,
K. -
Convert table from % to Pixels
Does anyone know how to convert table that is already full of
cells and text from % to pixels? I don't want to try and build
another table and copy the cell contents into it, this table is too
complex. You can see it at:
http://alternativecancer.us/#table2On Sun, 23 Dec 2007 17:33:39 +0000 (UTC), "Paul Winter"
<[email protected]> wrote:
>Does anyone know how to convert table that is already
full of cells and text
>from % to pixels? I don't want to try and build another
table and copy the
>cell contents into it, this table is too complex. You can
see it at:
>
http://alternativecancer.us/#table2
The link did not work
Either in the code - but if you are not happy with this,
ensure
properties box is open, then select the tables using the tag
selector
and enter the table width in pixels. Then select a column in
turn and
add the width of the column in pixels -
Horizontal Width
put the following into Dw's help system:
Resizing tables, columns, and rows
~Malcolm N....
~ -
Reformatting Table- convert columns to rows
Hi,
I have data tables that I would like to reformat so that the columns become rows and vice versa, if that is possible.
I've been keyword searching for hours, but unfortunately I am unfamiliar with the terminology... Sorry if this is really stupid; I'd appreciate any help! Thanks!Bev Kehoe wrote:
After calling Apple Tech support & having the tech head tell me 'transpose' only works on charts, we found you!
One more techie which doen't know what he respond about. The transpose function is not as efficient as we where hoping but it works.
Alas, the formulas are so weird that I thougt that the "transpose_live script is a better tool.
I was not able to find a 'menu' script within numbers but opened it on its own and it worked. Is there a way to have it be a choice within numbers itself?
The "Script menu" is a menu of its own.
If you apply what I described at the beginning of the script, you will have an area dedicated to Numbers.
We may organize the menu two ways:
Yvan KOENIG (from FRANCE lundi 29 juin 2009 16:57:49) -
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. -
Need help with query for converting columns to rows
Hello,
I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
I have a table which is having multiple columns as follows:
Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
Col1 Col2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
I 0Please anybody help me in writing the query for this..Is this what you are expecting:
SQL> WITH T AS
2 (
3 SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
4 )
5 SELECT 'X' col1, X col2 FROM T
6 UNION ALL
7 SELECT 'Y' col1, Y col2 FROM T
8 UNION ALL
9 SELECT 'Z' col1, Z col2 FROM T
10 UNION ALL
11 SELECT 'A' col1, A col2 FROM T
12 UNION ALL
13 SELECT 'B' col1, B col2 FROM T
14 UNION ALL
15 SELECT 'C' col1, C col2 FROM T
16 UNION ALL
17 SELECT 'D' col1, D col2 FROM T
18 UNION ALL
19 SELECT 'E' col1, E col2 FROM T
20 UNION ALL
21 SELECT 'F' col1, F col2 FROM T
22 UNION ALL
23 SELECT 'G' col1, G col2 FROM T
24 UNION ALL
25 SELECT 'H' col1, H col2 FROM T
26 UNION ALL
27 SELECT 'I' col1, I col2 FROM T
28 /
C COL2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
C COL2
I 0
12 rows selected.
Maybe you are looking for
-
Windows 8.1 Pro - Hyper-V Can I create a shareable disk?
I am using Windows 8.1 Pro with Hyper-V. Can I use a Synology NAS and create iSCSI LUNs which are shared between TWO virtual machines (running Linux) - a shareable disk. Or is this possible only in Windows 2012 Server? Thanks
-
Why do my CD tray keys no longer work?
I upgraded to 10.4.9 and now my cd eject tray key on my Apple extended keyboard no longer eject the CD trays. I can open them using the menu bar drop down menu. What's up?
-
Hi, we have installed EAS 11.1.1.3(64 bit) on weblogic 9.3.1 manually. But we identified one component was not deployed properly with weblogic n we were not able to solve it. as we dnt require EAS administration stuff we have not worried abt it, as w
-
Hello! I'have problem after i install on my toshiba a350D win7 x64 verssion, please some one can tell me , why when i install BLUETOOTH device, it show up with error, - PLEASE PLUG IN BLUETOOTH DEVICE== and then nothin' goin'on. so if there is the pr
-
Hello, I'm really new in photoshop and I would like to know how to change exposure settings in jpg images with photoshop. I have 100 pictures and would like to set exposure to +2,5 i all of them without editting one by one. How can I do that? Thankyo