Transpose columns and rows / Switch columns and rows
Hello,
Is it possible to interchange columns and rows in order to create a left-to-right scrolling table instead of a top-to-bottom scrolling one?
In detail:
I have this:
| col 1 | col 2 | col 3
row 1 | | |
row 2 | | |
row 3 | | |
... | | |
...and want to have this:
| row 1 | row 2 | row 3 | ...
col 1 | | | |
col 2 | | | |
col 3 | | | |
Does anyone know if this is possible with the standard table or the ALV?
Thanks in advance & Kind regards,
Robert
Hi,
So there is no easy solution by just setting a flag in the ALV config!? ...too bad!
As for the dynamic creation:
Would there be an issue with different data types in one "column" (former row)? As a matter of fact there probably will be a mix of character, numbers, ...
Regards,
Robert
Similar Messages
-
Transpose columns and rows in numbers
I need to transpose columns and rows in Numbers and I do not want to write script to do it. Is there an easier way?
Give me a proper transpose and I will uninstall Excel and never look back.
Ok, here's a proper transpose, that can be placed in an Automator Service so it becomes a simple menu pick as below (and can also be assigned a keyboard shortcut).
To use it (this is slightly different from Excel) you select the range you want to transpose, choose Copy Transpose, click a destination cell in an existing table in the current document or another document, and command-v (Edit > Paste) or option-shift-command-v (Edit > Paste and Match Style).
The one-time setup is as follows. In Automator choose File > New > Service, drag a Run AppleScript action from the left into the right pane, choose 'No Input' for 'Services receives selected' and 'Numbers' for 'in'. Then paste the following into the Run AppleScript action, replacing all text already there by default:
--Transpose - select range, run, paste transposed values where wanted
try
tell application "Numbers" to tell front document to tell active sheet
set selected_table to first table whose class of selection range is range
tell selected_table
set my_selection to the selection range
set first_col to address of first column of my_selection
set last_col to address of last column of my_selection
set first_row to address of first row of my_selection
set last_row to address of last row of my_selection
set str to ""
repeat with i from first_col to last_col
repeat with j from first_row to last_row
set str to str & (value of cell j of column i of selected_table) & tab
end repeat
set str to str & return -- add line return after row
end repeat
end tell
end tell
set the clipboard to str
display notification "Ready to paste transposed values" with title "Numbers"
on error
display dialog "Select a range first and then try again"
end try
--end script
Hit the compile "hammer" and the script should indent properly. Then save the service with the name you want to appear in your menu, and it will thereafter be available via the Services menu (and keyboard shortcut, if you set one up in System Preferences > Keyboard > Shortcuts > Services).
That's it. Less then five minutes' one-time set-up work and you've got a menu pick for a transpose functionality that is as convenient as Excel's.
SG -
How to transpose columns to rows in ODI
Hi,
I am trying to transpose Columns to rows along with Headers. For instance if i have
Account Name | Assigned To | Lead Source | Currency | Onsite_April |Offisite_April2 | FCST AMC LIC April
| | | | | |
Microsoft | Mark | Channel1 | INR | 1000 | 2000 | 3000
Then i need in the below way
Account Name | Assigned To | Lead Source | Currency | Month | Amount
| | | | |
Microsoft | Mark | Channel1 | INR | Onsite_April | 1000
Microsoft | Mark | Channel1 | INR | Offisite_April2 | 2000
Microsoft | Mark | Channel1 | INR | FCST AMC LIC April | 3000
Is there any specific function where i can achieve this?
More over i need break up Month column into two i.e Onsite_April will be Onsite (in one column) April (in another column).Hi
here is what i got by using the above KM
create table cad_temp_1(item_id number, location_id number, sales_date_ud1 varchar2(100), qty_ud2 number);
create table cad_temp_2(item_id number, location_id number, D01012010 number, D01022010 number);
insert into cad_temp_2 values(1,1,200,300);
commit;
Source in interface is : cad_temp_2
Target is: cad_temp_1
Mapping is
Item_id - Item_id execute on: CAD_TEMP_2 (Source selected) Update - Insert and Update checked
Location_id - Location_id execute on: CAD_TEMP_2 (Source selected) Update - Insert and Update checked
sales_date_ud1 - :NA execute on: <null> (Target selected) Update - Insert, Update, UD1 selected
qty_ud2 - :NA execute on : <null> (Target selected) Update - Insert, Update, UD2 selected.
Execute the interface
It works.
Thanks
Bhaskar -
Transposing columns to rows in excel through ODI
Hi all,
We are trying to transpose Columns to rows along with Headers considering excel as source and oracle table as target
For example we are having metadata and data in Excel sheet like below
Metadata:- A,B,TC1,TD1,L1,U1,TC2,TD2,L2,U2,TC3,TD3,L3,U3
Data:- X,Y,1,2,3,4,5,6,7,8,9,10,11,12
M,N,a,b,c,d,e,f,g,h,i,j,k,l
Then we need in the below way in oracle table
A,B,TC1,TD1,L1,U1
X,Y,1,2,3,4
X,Y,5,6,7,8
X,Y,9,10,11,12
M,N,a,b,c,d
M,N,e,f,g,h
M,N,i,j,k,l
Is there any process to achieve this?
If so Please let us know
Thanks in advanceHi SH,
Thanks for your reply
We already tried http://s3.amazonaws.com/Ora/KM_IKM_Pivot.zip by following the link https://community.oracle.com/thread/904535?tstart=0
But unfortunately we got the same error which is mentioned in that link
org.apache.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 35, in ?
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
I am newbie to odi - if possible can you please guide me how to do transpose in odi by considering excel as source and oracle as target
Thanks -
HI All,
I want to transpose columns to rows in my reports. I tried through Pivot Table and i was able to do that, but columns name are not appearing in the left.
Plz help me out how to do that with column name/
Can we do the same with measure also???
ThanksAll, thanks for the information.
I have a similar requirement as being discussed here. However, I do not have any measures in my report. It is a plain request which fetches data in three columns A, B and C (and variable number of rows depending on the data available).
Can I still use pivot table to transpose this data such that the resultant display would have three rows always and variable number of columns, with the first column containing the header A, B and C ? If yes, how do I go about it? Else, is there any other approach?
Thanks again
I
Edited by: user635102 on Sep 18, 2008 12:31 PM -
hi ,
i need to transpose columns into rows ,
i know i can use the UNION ALL but my num of columns will most likely not be fixed so how can i do that ?
pls adviseThis is from one of the forms link,, i reallyy dont know the link, but i guess this is "adrains" code
SQL> WITH ilv AS (
2 SELECT str || ',' AS str
3 , (LENGTH(str) - LENGTH(REPLACE(str, ','))) + 1 AS no_of_elements
4 FROM t
5 )
6 SELECT RTRIM(str, ',') AS original_string
7 , SUBSTR(str, start_pos, (next_pos-start_pos)) AS single_element
8 , element_no
9 FROM (
10 SELECT ilv.str
11 , nt.column_value AS element_no
12 , INSTR(
13 ilv.str,
14 ',',
15 DECODE(nt.column_value, 1, 0, 1),
16 DECODE(nt.column_value, 1, 1, nt.column_value-1)) + 1 AS start_pos
17 , INSTR(
18 ilv.str,
19 ',',
20 1,
21 DECODE(nt.column_value, 1, 1, nt.column_value)) AS next_pos
22 FROM ilv
23 , TABLE(
24 CAST(
25 MULTISET(
26 SELECT ROWNUM FROM dual CONNECT BY ROWNUM < ilv.no_of_elements
27 ) AS number_ntt )) nt
28 );
ORIGINAL_STRING SINGLE_ELEMENT ELEMENT_NO
X,Y,Z X 1
X,Y,Z Y 2
X,Y,Z Z 3
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG XXX 1
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG Y 2
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG ZZ 3
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG AAAAA 4
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG B 5
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG CCC 6
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG D 7
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG E 8
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG F 9
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG GGG 10
13 rows selected.
Note that the above SQL performs the following steps:
* determines how many elements are in each string (WITH clause);
* for each string, generates a collection of n elements (TABLE expression), where n is the derived number of elements in the string. Note in particular the use of "less than" in the "CONNECT BY ROWNUM < ilv.no_of_elements" on line 26. In all versions other than 10.1.x, this will need to be "CONNECT BY ROWNUM <= ilv.no_of_elements" (i.e. "less than or equal to"). There is an unusual bug with this row-generation technique in 10.1 that generates an additional row from the CONNECT BY;
* uses the generated rows in a Cartesian Product with the original data to generate n rows per string, based on the above definition of n;
* calculates the start and end position of each element in each string (INSTR); and
* cuts each element from each string (SUBSTR). -
How to Transpose series of rows & columns to singular inline column?
Hi gang!
Looking to do the reverse of my previous post (here: http://discussions.apple.com/message.jspa?messageID=9355192#9355192).
Specifically, looking to transpose from many rows & columns to 1 inline column...
from:
A1 A2 A3 A4 A5 A6 A7
B1 B2 B3 B4 B5 B6 B7
to:
A1
A2
A3
A4
A5
A6
A7
B1
B2
B3
B4
B5
B6
B7
For a whole set of data (over 330 rows of 7 columns)!
A function for doing the inverse was graciously provided in the previous post, but am stuck as to how to reverse it!
Previous (from 1 column to many):
INDEX(TRANSPOSE('Table_Src' :: B2:H2),7,1*(ROW()-2)+COLUMN()-1)
becomes... (from many to 1 column)
Anyone with ideas? Found the Function guide only more confusing! :OI would use this simple script:
--[SCRIPT] on run
set {rname, tName, sName, dName, colNum1, rowNum1, colNum2, rowNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
set liste to {}
repeat with r from rowNum1 to rowNum2
repeat with c from colNum1 to colNum2
copy value of cell r of column c to end of liste
end repeat
end repeat
end tell
set liste to my recolle(liste, return)
set the clipboard to liste
end run
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
if my parleAnglais() then
if r_Name is missing value then error "No sheet has a selected table."
else
if r_Name is missing value then error "Aucune feuille ne contient une table sélectionnée."
end if
set two_Names to my decoupe(r_Name, ":")
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table t_Name
set col_Num1 to address of column of cell (item 1 of two_Names)
set row_Num1 to address of row of cell (item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {col_Num2, row_Num2} to {col_Num1, row_Num1}
else
set col_Num2 to address of column of cell (item 2 of two_Names)
set row_Num2 to address of row of cell (item 2 of two_Names)
end if
end tell -- _Numbers …
return {r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2}
end getSelParams
--=====
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theRange, theTable, theSheet, theDoc}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
Select the range to transpose
Run the script
paste where you want.
Yvan KOENIG (from FRANCE lundi 4 mai 2009 15:17:08) -
Transposing group from rows to column
Hi Team,
I am having groups of rows of a fixed kind that need to be transposed to column. eg
Attrib
Value
Attribute1
a
Attribute2
b
Attribute3
c
Attribute4
d
Attribute1
e
Attribute2
f
Attribute3
g
Attribute4
h
Attribute2
i
Attribute3
j
Attribute4
k
This need to be transposed as ;
Attribute1
Attribute2
Attribute3
Attribute4
a
b
c
d
e
f
g
h
NULL
i
j
k
Any help would be great...
I tried using PIVOT like
pivot (min (AttributeValue) for rn in ([1], [2], [3], [4],[5], [6])) pvt
where i was having rank in rn... but the places where Attribute1 is not present, that also nneed to become NULL. This is something I am not able to do.Hi
If
I may, there is very small fix to
Rishabh's query in order to make it work.
* as it is it will work only if the order of the insert fit the result, and not in any case! the SQL Server might bring the data in different order if there is no use of ORDER BY
Option 1:
;with cte as
SELECT * , ROW_NUMBER () OVER (partition by Attrib ORDER BY (SELECT NULL)) as rnum
FROM T
--select * from cte
select [Attribute1],[Attribute2],[Attribute3],[Attribute4]
FROM
SELECT Attrib,Value , rnum
FROM cte
)p
PIVOT
(MAX(value) FOR Attrib IN ([Attribute1],[Attribute2],[Attribute3],[Attribute4]))pvt
Option 2: Another option for solution might be
;with MyCTE as (
select Attrib, Value, ROW_NUMBER() OVER (partition by Attrib order by (SELECT NULL)) RN
from T
select
MAX(CASE when Attrib = 'Attribute1' then Value END) as Attribute1
,MAX(CASE when Attrib = 'Attribute2' then Value END) as Attribute2
,MAX(CASE when Attrib = 'Attribute3' then Value END) as Attribute3
,MAX(CASE when Attrib = 'Attribute4' then Value END) as Attribute4
--, RN
from MyCTE
group by RN
And here is all together (check your solution which is the first, it will not bring the correct result since I changed the order of inserted)
create table T (Attrib NVARCHAR(100), Value NVARCHAR(10))
insert T values
('Attribute1', 'a'),
('Attribute2', 'b'),
('Attribute3', 'j'),
('Attribute3', 'c'),
('Attribute4', 'd'),
('Attribute1', 'e'),
('Attribute2', 'f'),
('Attribute3', 'g'),
('Attribute4', 'h'),
('Attribute2', 'i'),
('Attribute4', 'k')
GO
;with cte as
SELECT * , (ROW_NUMBER () OVER (ORDER BY (SELECT NULL)) -1 )/ 4 as rnum
FROM T
--select * from cte
select [Attribute1],[Attribute2],[Attribute3],[Attribute4]
FROM
SELECT Attrib,Value , rnum
FROM cte
)p
PIVOT
(MAX(value) FOR Attrib IN ([Attribute1],[Attribute2],[Attribute3],[Attribute4]))pvt
GO -- Not OK
;with MyCTE as (
select Attrib, Value, ROW_NUMBER() OVER (partition by Attrib order by (SELECT NULL)) RN
from T
select
MAX(CASE when Attrib = 'Attribute1' then Value END) as Attribute1
,MAX(CASE when Attrib = 'Attribute2' then Value END) as Attribute2
,MAX(CASE when Attrib = 'Attribute3' then Value END) as Attribute3
,MAX(CASE when Attrib = 'Attribute4' then Value END) as Attribute4
--, RN
from MyCTE
group by RN
GO -- OK
;with cte as
SELECT * , ROW_NUMBER () OVER (partition by Attrib ORDER BY (SELECT NULL)) as rnum
FROM T
--select * from cte
select [Attribute1],[Attribute2],[Attribute3],[Attribute4]
FROM
SELECT Attrib,Value , rnum
FROM cte
)p
PIVOT
(MAX(value) FOR Attrib IN ([Attribute1],[Attribute2],[Attribute3],[Attribute4]))pvt
GO --OK
drop table T
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
Sql Transposing Column Name in Row
i am using Sql Server 2008
tbl_EmployeeProfile
EmployeeId EmployeeName LeaveApplicable Active
1 Sam true true
2 Rahul false false
3 Sameer true true
tbl_MasterLeave
id LeaveCode Description active
1 PL Paid Leave true
2 CL Casual Leave true
3 SL Sick Leave false
tble_LeaveAllocation
EmployeeId Period 1 2 3 .........31
1 2014 18 4
3 2014 20 4
note: tble_Masterleave.id = tble_LeaveAllocation.1( column Name)
i.e value of tbl_masterleave id is mape with column name of tble_LeaveAllocation 1,2,.....31
Expected out put
EmployeeId EmployeeeName Period PL CL
1 Sam 2014 18 4
3 Sameer 2014 20 4
Note: show only record who is active = true & leaveApplicable = true .
why i made this table structure because non of organization leave type are not fixed, so user can customize leave according their requirment , so i made tbl_ allocation table with 1 to 31 column , so user can allocate leave type max 31.
please advice me is it right method or any other good alternative solution
Thanks Best Regard NaweezPlease follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
Why are you so special that you do not have to post DDL? I Googled you and got nothing that would grant you privilege.
You have the manners of a pig and your code is garbage. Look up tibbling in the “code smells” paper. That is what we call your “tbl-”
prefix when we laugh at you.
Why do you write SQL with assembly language flags? SQL programmers do not! Why did you use the term “master_” on a table name? This term is from tape files and network DB; it has nothing to do with RDBMS!!
Why do you think that “active” is an attribute? NO! It is a value of some particular attribute and needs a temporal range.
There is no generic “id” in RDBMS! Remember the Law of Identity from your first freshman logic class? Rows are not records, so you got that term wrong. We do not use mappings in RDBMS; we have REFERENCES.
CREATE TABLE Personnel
(emp_id CHAR(10) NOT NULL PRIMARY KEY,
emp_name VARCHAR(35) NOT NULL);
CREATE TABLE Leave_Codes
(leave_code CHAR(2) NOT NULL PRIMARY KEY,
leave_code_description VARCHAR (20) NOT NULL);
INSERT INTO Leave_Codes
VALUES
('PL', 'Paid Leave'),
('CL', 'Casual Leave'),
('SL', 'Sick Leave);
I might have done this:
CREATE TABLE Employee_Leaves
(emp_id CHAR(10) NOT NULL
REFERENCES Personnel(emp_id)
leave_start_date DATE NOT NULL,
leave_end_date DATE NOT NULL,
CHECK(leave_start_date < leave_end_date),
leave_code CHAR(2) NOT NULL
REFERENCES Leave_Codes (leave_code),
PRIMARY KEY (??),
>> why I made this table structure because our organization leave type are not fixed, so user can customize leave according their requirement, so I made allocation table with 1 to 31 column, so user can allocate leave type max 31. <<
No, you did this out of ignorance. You do not understand RDBMS or SQL. YHou do not know any of the basics.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Transposing of queried rows into columns
Hi, i have a query that produces an output of several rows (i.e. no. of days in a month). How do I modify my query so that instead of getting 31 rows for january, I will have one row with 31 columns or values? Thank you.
Thank you very much for your response. You definitely got what i wanted to do but honestly, I'm having a hard time applying this to my query since I am not very familiar with the WITH AS, CONNECT BY LEVEL and the PRIOR commands, coupled with the fact that I have to produce my output ASAP. I have this query:
SELECT A.PLTCODE, A.PLTACTLGEN, A.INPTDATE
FROM PMC_ACTLGEN A
WHERE A.INPTDATE >
TO_DATE ('10/31/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
AND A.INPTDATE <
TO_DATE ('01/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
ORDER BY --
A.PLTCODE, A.INPTDATE
which produce an output that looks like this:
PLTCODE
PLTACTLGEN
INPTDATE
AMB
0
11/1/2013
AMB
204
11/2/2013
AMB
107
11/3/2013
AMB
968
11/4/2013
AMB
1379
11/5/2013
AMB
1493
11/6/2013
AMB
1457
11/7/2013
AMB
1099
11/8/2013
AMB
1893
11/9/2013
AMB
2517
11/10/2013
AMB
2521
11/11/2013
AMB
2448
11/12/2013
AMB
701
11/13/2013
AMB
1785
11/14/2013
AMB
2002
11/15/2013
AMB
1601
11/16/2013
AMB
1225
11/17/2013
AMB
1572
11/18/2013
AMB
1579
11/19/2013
AMB
1576
11/20/2013
AMB
1722
11/21/2013
AMB
1610
11/22/2013
AMB
175
11/23/2013
AMB
813
11/24/2013
AMB
1674
11/25/2013
AMB
2198
11/26/2013
AMB
1841
11/27/2013
AMB
1970
11/28/2013
AMB
1918
11/29/2013
AMB
721
11/30/2013
How do I exactly modify this query to produce an output such that the INPTDATE is arranged as columns e.g.
INPTDATE 1 2 3 4 5 6 7 . . . 30
AMB 0 204 107 968 1379 1493 1457 . . . 721
PLEASE HELP! Thanks a lot! -
How to transpose columns to rows?
Hi,
here is my situation and I would love is someone could give me some help.
This is how my data is currently presented(first line represents the header, the second line represents the value:
Number A1 A2 B1 B2 C1 C2
001187 1 2 1 6 1 1
and I would need to get it into the following format:
Number A B C
001187 1 1 1
001187 2 6 1
In summary all values from columns with same start name should be transposed into one column.
Would anyone have any suggestions?Assuming you have one table that has the columns : Number A1 A2 B1 B2 C1 C2
then something like :
select number, a, b, c
from (select 1 the_order, number, a1 a, b1 b, c1 c
from table
union all
select 2 the_order, number, a2 a, b2 b, c2 c
from table)
order by number, the_order -
Transpose columns into rows-Please Help
Hi,
I have a table(test_data) in following format:
F_P reference_id first_nm last_nm
EM_NULL 0 0 0
EM_NOT_NULL 0 0 0
DM_NULL 1296 145 1689
DM_NOT_NULL 0 0 0I need to transpose the the above table as :
Column_Name EM_NULL EM_NOT_null DM_null DM_not_null
Reference_ID 0 0 1296 0
first_nm 0 0 145 0
last_nm 0 0 1689 0I tried below code but unable to get the first column values as reference_id,first_nm,last_nm although I was successful in getting the other column values.Below is the code:
With
lines as (select level line from dual connect by level <= 3),
cols as (select level col from dual connect by level <= 3)
select
max(decode(col, 1,
decode(line, 1, to_number('REFERENCE_ID') ,
2, to_number('FIRST_NM'),
3, to_number('LAST_NM')
)))column_name,
max(decode(col, 2,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))EM_NULL,
max(decode(col, 3,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))EM_NOT_NULL,
max(decode(col, 4,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))DM_NULL,
max(decode(col, 5,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))DM_NULL
from lines, cols,
(select rownum rn, TEST_DATA.* from Test_Data)
where rn = col
group by line
order by lineBut since my 1st column values are character its not allowing me the group by function.
Edited by: BluShadow on 23-Sep-2011 08:31
formatted and added {noformat}{noformat} tags.I think you want something like this...
SQL> ed
Wrote file afiedt.buf
1 with test_data as (select 'EM_NULL' as f_p, 0 as reference_id, 0 as first_nm, 0 as last_nm from dual union all
2 select 'EM_NOT_NULL', 0, 0, 0 from dual union all
3 select 'DM_NULL', 1296, 145, 1689 from dual union all
4 select 'DM_NOT_NULL', 0, 0, 0 from dual)
5 --
6 -- end of test data
7 --
8 select decode(rn,1,'Reference_ID',2,'first_nm',3,'last_nm') as Column_name
9 ,max(decode(f_p,'EM_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as EM_NULL
10 ,max(decode(f_p,'EM_NOT_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as EM_NOT_NULL
11 ,max(decode(f_p,'DM_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as DM_NULL
12 ,max(decode(f_p,'DM_NOT_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as DM_NOT_NULL
13 from test_data, (select rownum rn from dual connect by rownum <= 3)
14 group by decode(rn,1,'Reference_ID',2,'first_nm',3,'last_nm')
15* order by decode(Column_name,'Reference_ID',1,'first_nm',2,3)
SQL> /
COLUMN_NAME EM_NULL EM_NOT_NULL DM_NULL DM_NOT_NULL
Reference_ID 0 0 1296 0
first_nm 0 0 145 0
last_nm 0 0 1689 0Unless you're using 11g and then you could look at the new PIVOT/UNPIVOT keywords -
How to transpose columns to rows in OBIEE
Lets say I have a row of data with 3 columns as shown below.
Col1 Col1 Col3
Val1 Val2 Val3
How can this be shown as 3 rows as below
Col 1 Val1
Col 2 Val2
Col 3 Val2
Thanks.Use the Narrative View
Prefix: <table border=1>
Narrative:
<tr><td>Col1</d><td>@1</td></tr>
<tr><td>Col2</d><td>@2</td></tr>
<tr><td>Col3</d><td>@3</td></tr>
Postfix:
</table>
Enjoy! -
Unable to Transpose Columns to Rows in DataExport Command
Hi,
The Data export code for On and Off Gives me the same result
SET LOCKBLOCK HIGH;
SET CACHE HIGH;
SET CALCPARALLEL 3;
SET DATAEXPORTOPTIONS
DataExportLevel "LEVEL0";
DataExportColFormat ON;
DataExportOverwriteFile ON;
DataExportDimHeader OFF;
DataExportRelationalFile ON;
DataExportColHeader "Scenario";
FIX ("SAP",&CurrFcst,&Currmnth:Sep,"Forecast Employees",&CurrFY,@IDescendents("All_Cost_Center"),@IDescendents("Pay Type"),@IDescendents("Work Type"),@IDescendents("Other_Accounts")
DATAEXPORT "File" "," $DataExportPath "0";
ENDFIX;
ENDFIX;
Result
WT"|"Non-Exempt"|7|5|5|5|5|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30100"|"Forecast Employees"|"Full-Time"|"Indirect WT"|"Exempt"|3|3|3|3|3|3|3|3|3|3
"SAP"|"FY13"|"Plan"|"A100C30110"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|8|6|6|6|6|6|6|6|6|6
"SAP"|"FY13"|"Plan"|"A100C30120"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|7|4|4|4|4|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30130"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|4|4|4|4|4|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30160"|"Forecast Employees"|"Full-Time"|"Indirect WT"|"Exempt"|5|4|4|4|4|3|3|3|3|3
The way that i want the Data to be Represented is
SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jan" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Feb" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Mar" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Apr" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "May" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jun" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jul" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Aug" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Sep" 4.0000
I believe that this issue is because of the Range that is used (&Currmnth:Sep)
Could Someone help on this Issue.
Thanks,
JoeI hope below code will give you result desired format, changes I made are in bold and italics
SET LOCKBLOCK HIGH;
SET CACHE HIGH;
SET CALCPARALLEL 3;
SET DATAEXPORTOPTIONS
DataExportLevel "LEVEL0";
DataExportColFormat OFF;
DataExportOverwriteFile ON;
DataExportDimHeader OFF;
DataExportRelationalFile ON;
+/*DataExportColHeader "Scenario"*/+;
FIX ("SAP",&CurrFcst,&Currmnth:Sep,"Forecast Employees",&CurrFY,@IDescendents("All_Cost_Center"),@IDescendents("Pay Type"),@IDescendents("Work Type"),@IDescendents("Other_Accounts")
DATAEXPORT "File" "," $DataExportPath "0";
ENDFIX;
ENDFIX; -
Transposing column names to row for a multi row table
Hi
I have a table some thing like this that needs to be transposed.
FIELD_POPULATED First_NM**Last_NM**Mi_NM*
A_NULL 0 0 0
A_NOT_NULL 120 120 120
B_NULL 0 0 0
B_NOT_NULL 0 0 0
The above table has to be transposed as
column_name*A_NULL**A_NOT_NULL**B_NULL* B_NOT_NULL
FIRST_NM 0 120 0 0
Last_NM 0 120 0 0
Mi_NM 0 120 0 0
I am working oracle on 11g. Any help is greatly appreciatedHi,
See this thread:
Re: Help with PIVOT query (or advice on best way to do this)
Maybe you are looking for
-
Vi works in LabVIEW, but not when executed by TestStand.
Hi everybody. I'm using LabVIEW 8 with the Sound and Vibration Toolkit, and TestStand2. I am planning on using TestStand to execute a series of performance tests on an audio processing board. When run independently, the vi (which I have attached h
-
I purchased a sun ultra 5 used that is supposed to have solaris 8 on it. When I try to boot from the disk it begins to boot and then I get a : SUNW,hme0: No response from ethernet network: Link down--cable problem? followed by a Starting IPv4 routing
-
Hi Experts, I am on ERP2004 SP17 EP6.0 SP20. I am trying to implemet Time Statement application. I am getting the error "Form name PYXXFO_SAP_TIM_99_0001 not active for form SAP_TIM_99_0001" on portal when trying to access the time statement. Where c
-
How do i print a document from a mac to a dell 5100cn printer wirelessly
Having a problem printing wirelessly from a macbook pro to a Dell 5100cn printer. I have entered the IP address for the printer on the mac and it appears that the printer did receive the command from the Mac but it says that it is printing and a mes
-
Need SAP BPC Material for Starter
Hi All, 1 st of all, I would like to introcduce about my self, I am Kiran, I have completed my Masters in 2009 and now i am in QA Testing, i just want to move to SAP. In my research, my friends suggesting to learn SAP BPC. Now i am confused, can any