Transporting columns into rows using SSIS
Hi everyone,
Just need some help.
I wanna transpose a data table in SSIS.
The table is originally
CUSTREFNO
Citizen
FORENAME
Citizen
SURNAME
Citizen
DATE-OF-BIRTH
Citizen
TEL_NO
Citizen
GUARDIANNAME
Citizen
ADDRESS1
Citizen
ADDRESS2
Citizen
ADDRESS3
Citizen
ADDRESS4
Citizen
POSTTOWN
Citizen
POSTCODE
Citizen
OPERATOR
Junk
BOARDINGPOINT
Junk
DESTINATION
Junk
SERVICE_NO
Junk
EMAIL
Citizen
And i need the table in the following format
CUSTREFNO
FORENAME
SURNAME
DATE-OF-BIRTH
TEL_NO
GUARDIANNAME
ADDRESS1
ADDRESS2
ADDRESS3
ADDRESS4
POSTTOWN
POSTCODE
OPERATOR
BOARDINGPOINT
DESTINATION
SERVICE_NO
EMAIL
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Junk
Junk
Junk
Junk
Citizen
Any help, would be very much appreciated, thanks
Umar, please see these resources.
http://blogs.msdn.com/b/philoj/archive/2007/11/10/transposing-rows-and-columns-in-sql-server-integration-services.aspx
http://www.rad.pasfu.com/index.php?/archives/14-PIVOT-Transformation-SSIS-Complete-Tutorial.html
http://dinesql.blogspot.in/2011/08/pivot-and-unpivot-integration-services.html
http://sqlage.blogspot.in/2013/12/ssis-how-to-use-unpivot-in-ssis.html
http://www.bimonkey.com/2009/06/the-pivot-transformation/
http://www.sql-server-performance.com/2007/ssis-pivot-unpivot/
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
Similar Messages
-
How to convert columns into rows using transpose function
Hi
anybody tell me how to convert columns values into rows using transpose function.Since BluShadow went to all the trouble to put it together, someone should use it.
See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
John -
Split multiple columns into rows using XML
Hi Forum,
I am trying to split 2 columns that each contain values separated by semicolon into single rows. The relation between the values of the two columns is that the order in the cells corresponds to each other.
The data looks like this:
pk Manufacturer partnumber
1 Man1; Man2;Man3 PN1;PN2;PN3
2 Man4; Man2;Man5 PN4;PN5;PN6
The result should be:
pk Manufacturer partnumber
1 Man1 PN1
1 Man2 PN2
1 Man3 PN3
2 Man4 PN4
2 Man2 PN5
2 Man5 PN6
I am not sure how to format the XML to get a useful Basis for XML.value or XML.query
Any ideas?
TIA
AlexHi,
Try like this ,
DECLARE @tmp TABLE (pk INT,Manufacturer NVARCHAR(50),partnumber NVARCHAR(50))
INSERT @tmp SELECT 1,'Man1; Man2;Man3','PN1;PN2;PN3'
INSERT @tmp SELECT 2,'Man4; Man2;Man5','PN4;PN5;PN6'
SELECT * FROM @tmp
SELECT tmp2.pk pk,Manufacturer,partnumber FROM (
SELECT ROW_NUMBER()OVER(ORDER BY tmp1.pk) RN,* FROM (
SELECT pk,
LTRIM(i.value('.','varchar(100)')) Manufacturer
FROM ( SELECT pk, Manufacturer,
CONVERT(XML,'<r><n>'
+ REPLACE(Manufacturer,';', '</n><n>') + '</n></r>') AS X
FROM @Tmp) Spt
CROSS APPLY Spt.X.nodes('//*[text()]') x(i)
) tmp1 ) tmp2
JOIN
(SELECT ROW_NUMBER()OVER(ORDER BY pk) RN,* FROM (
SELECT pk,
j.value('.','varchar(100)') partnumber
FROM ( SELECT pk, partnumber,
CONVERT(XML,'<r><n>'
+ REPLACE(partnumber,';', '</n><n>') + '</n></r>') AS Y
FROM @Tmp) Spt
CROSS APPLY Spt.Y.nodes('//*[text()]') y(j)) tmp2 ) tmp3 ON tmp3.RN = tmp2.RN
sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **. -
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 -
How to display the rows in to columns and columns into rows?
DES:- I know by using pivot and unpivot you can convert rows into columns and columns into rows but i don't know how to write the syntax?
Hi,
Besides the places Martin mentioned above, there are many examples in the forum FAQ:
https://community.oracle.com/message/9362005#9362005
For an example of both PIVOT and UNPIVOT in the same query, see
http://forums.oracle.com/forums/thread.jspa?threadID=920854&tstart=0 -
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). -
Hi All,
I need help in building view which actually can show columns data as row.
e.g.
row is as follows
Name Age Salary
ABC 25 10000
BBC 28 12000
The above tables data I want to get as
Name ABC BBC
Age 25 28
Salary 10000 12000
Thanks in advance.Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
Re: Converting Columns into rows
Nicolas. -
Hi. Does anyone know how to turn columns into rows ie:
select field1, field2, field3, field4, field5 from table
desired result:
field1 field2
field1 field3
field1 field4
field1 field5
Thank you!Something like this ?
select field1
, case n.l
when 1 then field2
when 2 then field3
when 3 then field4
when 4 then field5
end field
from table
, (select level l from dual connect by level <= 4) n -
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 -
I have data in a table that looks like below:
ColumnA ColumnB
123 abc|cde|fgr
345 def|ght|sew
890 deq|nmk|lop|lip|fre|dwsThere is no limit on how many values you can have in ColumnB and they are pipe delimited.
I need to split this one column into rows as:
ColumnA ColumnB
123 abc
123 cde
123 fgr
345 def
345 ght
890 fre
890 dwsThanks in advance!with sample_data as (
select 123 columna,'abc|cde|fgr' columnb from dual union all
select 345,'def|ght|sew' from dual union all
select 890,'deq|nmk|lop|lip|fre|dws' from dual
select columna,
regexp_substr(columnb,'[^|]+',1,column_value) columnb
from sample_data,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(columnb || '|','[^|]'))
as sys.OdciNumberList
order by columna,
column_value
COLUMNA COLUMNB
123 abc
123 cde
123 fgr
345 def
345 ght
345 sew
890 deq
890 nmk
890 lop
890 lip
890 fre
COLUMNA COLUMNB
890 dws
12 rows selected.
SQL> SY. -
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. -
Hello everyone,
I am developing an application (ALV OO) to select more than 1 column by row ( one ). This is an a holiday application so the idea is:
-One column will be the day, and the row will be the user.
So I am trying to select more than one day by user (that would be the row).
I am using the method set_table_for_first_display but when it shows the alv, doesn't let me to select more than one column with a click of the mouse.
Does anybody know if I can do this (select more than one column, by row) in somehow?
Please let me know if you need more clarification about this.
Thanks in advance
DiegoHi Diego,
it's all in the documentation.
set different selection modes through the value of the field u201CSEL_MODEu201D in the layout structure.
SPACE
same as 'B'
see 'B'
Default setting
'A'
Column and row selection
Multiple columns
Multiple rows
The user selects the rows through pushbuttons at the left border of the grid control.
'B'
Simple selection, list box
Multiple columns
Multiple rows
'C'
Multiple selection, list box
Multiple columns
Multiple rows
'D'
Cell selection
Multiple columns
Multiple rows
Any cells
The user selects the rows through pushbuttons at the left border of the grid control
Beyond setting this option, you can set u201CNO_ROWMARKu201D option to hide the mark column which is normally visible when the selection mode allows multiple row selection.
One point to notice here is that if you set your ALV Grid as to be editable, it may override your selection mode regardless of your layout settings.
This is from SDN Community Contribution "An Easy Reference for ALV Grid Control" By: Serdar ŞİMŞEKLER
Sorry, no link,. it's on my disk.
Regards,
Clemens -
How to split columns into rows
Hi All,
Below is my table structure:=
SQL> create table split(id number,value varchar2(200));
Table created.
SQL> insert into split values(1,'X,Y,Z');
1 row created.
SQL> insert into split values(2,'A,B,C');
1 row created.
SQL> commit;
Commit complete.
Expected Output
ID Value
1 X
1 Y
1 Z
2 A
2 B
3 C
I know the feature of converting rows into columns by listagg in Oracle 11g, but is there any feature to convert rows into columns based on a delemiter..."," in my case.
Please help....
Thanks
Arijit>
is there any feature to convert rows into columns based on a delemiter
>
Here is one way
VAR csv VARCHAR2(100)EXEC :csv := 'abc,de,fg,hij,klmn,o,pq,rst,uvw,xyz';
The query:
WITH data AS( SELECT SUBSTR(csv, INSTR(csv,',',1,LEVEL)+1, INSTR(csv,',',1,LEVEL+1) - INSTR(csv,',',1,LEVEL)-1 ) token FROM ( SELECT ','||:csv||',' csv FROM SYS.DUAL ) CONNECT BY LEVEL < LENGTH(:csv)-LENGTH(REPLACE(:csv,',',''))+2 )SELECT token FROM data;See http://projectwownow.blogspot.com/2010/02/oracle-convert-csv-string-into-rows.html -
Tranforming columns into rows taking to long
Hi,
Please help me in tuning the query. I am trying to transform rows into columns. Its taking lots of time almost 13hrs for 500k records.
select
decode ( r,
1,Col_1,
2,Col_2,
3,Col_3,
4,Col_4,
5,Col_5,
6,Col_6,
7,Col_7,
8,Col_8,
9,Col_9,
10,Col_10,
11,Col_11,
12,Col_12,
13,Col_13,
14,Col_14,
15,Col_15,
16,Col_16,
17,Col_17,
18,Col_18,
19,Col_19,
20,Col_20) Col,
R ,
decode ( r,
1,CASE WHEN SUBSTR(T1.Date_1,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_1,'YYYYDDD') ELSE NULL END,
2,CASE WHEN SUBSTR(T1.Date_2,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_2,'YYYYDDD') ELSE NULL END,
3,CASE WHEN SUBSTR(T1.Date_3,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_3,'YYYYDDD') ELSE NULL END,
4,CASE WHEN SUBSTR(T1.Date_4,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_4,'YYYYDDD') ELSE NULL END,
5,CASE WHEN SUBSTR(T1.Date_5,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_5,'YYYYDDD') ELSE NULL END,
6,CASE WHEN SUBSTR(T1.Date_6,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_6,'YYYYDDD') ELSE NULL END,
7,CASE WHEN SUBSTR(T1.Date_7,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_7,'YYYYDDD') ELSE NULL END,
8,CASE WHEN SUBSTR(T1.Date_8,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_8,'YYYYDDD') ELSE NULL END,
9,CASE WHEN SUBSTR(T1.Date_9,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_9,'YYYYDDD') ELSE NULL END,
10,CASE WHEN SUBSTR(T1.Date_10,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_10,'YYYYDDD') ELSE NULL END,
11,CASE WHEN SUBSTR(T1.Date_11,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_12,'YYYYDDD') ELSE NULL END,
12,CASE WHEN SUBSTR(T1.Date_12,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_12,'YYYYDDD') ELSE NULL END,
13,CASE WHEN SUBSTR(T1.Date_13,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_13,'YYYYDDD') ELSE NULL END,
14,CASE WHEN SUBSTR(T1.Date_14,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_14,'YYYYDDD') ELSE NULL END,
15,CASE WHEN SUBSTR(T1.Date_15,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_15,'YYYYDDD') ELSE NULL END,
16,CASE WHEN SUBSTR(T1.Date_16,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_16,'YYYYDDD') ELSE NULL END,
17,CASE WHEN SUBSTR(T1.Date_17,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_17,'YYYYDDD') ELSE NULL END,
18,CASE WHEN SUBSTR(T1.Date_18,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_18,'YYYYDDD') ELSE NULL END,
19,CASE WHEN SUBSTR(T1.Date_19,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_19,'YYYYDDD') ELSE NULL END,
20,CASE WHEN SUBSTR(T1.Date_20,5) BETWEEN '001' AND '366'
THEN TO_DATE(T1.Date_20,'YYYYDDD') ELSE NULL END)
Date from Table_1 t1,(select level R from dual connect by level <= 20)
where decode ( r,
1,Col_1,
2,Col_2,
3,Col_3,
4,Col_4,
5,Col_5,
6,Col_6,
7,Col_7,
8,Col_8,
9,Col_9,
10,Col_10,
11,Col_11,
12,Col_12,
13,Col_13,
14,Col_14,
15,Col_15,
16,Col_16,
17,Col_17,
18,Col_18,
19,Col_19,
20,Col_20) !=0
thanks
Edited by: user627047 on Jun 23, 2009 12:07 AMHere I managed to get the output
PLAN_TABLE_OUTPUT
Plan hash value: 2442671038
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 408 | 274K| 40 (43)| 00:00:01 |
| 1 | NESTED LOOPS | | 408 | 274K| 40 (43)| 00:00:01 |
| 2 | VIEW | | 1 | 13 | 2 (0)| 00:00:01 |
|* 3 | CONNECT BY WITHOUT FILTERING| | | | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 5 | EXTERNAL TABLE ACCESS FULL | EVP0010 | 408 | 269K| 38 (45)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter(LEVEL<=20)
5 - filter(DECODE("R",1,"C_LOGO_LYLTY_CARD_1",2,"C_LOGO_LYLTY_CARD_2",3,"C_LOGO
_LYLTY_CARD_3",4,"C_LOGO_LYLTY_CARD_4",5,"C_LOGO_LYLTY_CARD_5",6,"C_LOGO_LYLTY_CAR
D_6",7,"C_LOGO_LYLTY_CARD_7",8,"C_LOGO_LYLTY_CARD_8",9,"C_LOGO_LYLTY_CARD_9",10,"C
_LOGO_LYLTY_CARD_10",11,"C_LOGO_LYLTY_CARD_11",12,"C_LOGO_LYLTY_CARD_12",13,"C_LOG
O_LYLTY_CARD_13",14,"C_LOGO_LYLTY_CARD_14",15,"C_LOGO_LYLTY_CARD_15",16,"C_LOGO_LY
LTY_CARD_16",17,"C_LOGO_LYLTY_CARD_17",18,"C_LOGO_LYLTY_CARD_18",19,"C_LOGO_LYLTY_
CARD_19",20,"C_LOGO_LYLTY_CARD_20")<>0)
24 rows selected. -
Mild challenge -pivoting *multiple* columns per row using only SQL
Hello All,
I'm in the process of learning the various pivoting techniques available
in SQL, and I am becoming more familiar with the decode,function,group-by
technique seen in many examples on these forums. However, I've got a case
where I need to pivot out 3 different columns for 3 rows of data where the
value of a different column is driving whether or not those columns are pivoted.
I know that last sentence was as clear as mud so I'll show you/provide the simple
scripts and data, and then I'll elaborate a little more beneath.
create table temp_timeline (
mkt_id varchar2(10),
event_id number(8),
event_type varchar2(3),
mod_due_date date,
cur_due_date date,
act_due_date date
insert into temp_timeline values('DSIM6',51,'S1','NOV-13-06','NOV-13-06',NULL);
insert into temp_timeline values('DSIM6',51,'S2','DEC-20-06','DEC-20-06',NULL);
insert into temp_timeline values('DSIM6',51,'S3','JAN-17-07','JAN-17-07',NULL);
insert into temp_timeline values('DSIM6',51,'S4','FEB-14-07','FEB-14-07',NULL);
commit;
select * from temp_timeline;
The "normal" output (formatted with period-separated fields) is:
DSIM6.51.S1.NOV-13-06.NOV-13-06.NULL
DSIM6.51.S2.DEC-20-06.DEC-20-06.NULL
DSIM6.51.S3.JAN-17-07.JAN-17-07.NULL
DSIM6.51.S4.FEB-14-07.FEB-14-07.NULL
The DESIRED 1-row output (formatted with period-separated fields) is:
DSIM6.51.NOV-13-06.NOV-13-06.NULL.DEC-20-06.DEC-20-06.NULL.JAN-17-07.JAN-17-07.NULL.FEB-14-07.FEB-14-07.NULL
So, the first 2 columns in the table have the same data, and the third column
makes the row unique (they could all have the same/similar dates).
If this table only consisted of the first 3 columns then many of the examples seen
on this forum would work well (grouping by the first 2 rows and pivoting out
the "event_type" columns containing (S1,S2,S3,S4) etc.
But, in my case, I need to discard the event_type column and pivot out the
3 columns of date data onto the first row (for each different event_type).
So the 3 Dates associated with the "S2" column would go to the first row, and the
3 dates associated with the "S3" column would also go to the first row (and so on).
The 3 dates need to be 3 distinct columns when they are
pivoted out (not concatenated to each other and pivoted as one column).
Given this, I will need to pivot out a total of 12 different columns for each distinct
(mkt_id, event_id) pair.
For the time being I have accomplished this with a union, but am trying to expand
my abilities with other sql methods. I've seen some very elegant solutions on this
forum so will be interested to see what others can come up with for this solution.
Thanks in advance for any comments you may provide.Just DECODE based on the event type, which will generate your 12 columns.
SELECT mkt_id, event_id,
MAX(DECODE(event_type, 'S1', mod_due_date, NULL)) s1_mod_due,
MAX(DECODE(event_type, 'S1', cur_due_date, NULL)) s1_cur_due,
MAX(DECODE(event_type, 'S1', act_due_date, NULL)) s1_act_due,
MAX(DECODE(event_type, 'S2', mod_due_date, NULL)) s2_mod_due,
MAX(DECODE(event_type, 'S2', cur_due_date, NULL)) s2_cur_due,
MAX(DECODE(event_type, 'S2', act_due_date, NULL)) s2_act_due,
MAX(DECODE(event_type, 'S3', mod_due_date, NULL)) s3_mod_due,
MAX(DECODE(event_type, 'S3', cur_due_date, NULL)) s3_cur_due,
MAX(DECODE(event_type, 'S3', act_due_date, NULL)) s3_act_due,
MAX(DECODE(event_type, 'S4', mod_due_date, NULL)) s4_mod_due,
MAX(DECODE(event_type, 'S4', cur_due_date, NULL)) s4_cur_due,
MAX(DECODE(event_type, 'S4', act_due_date, NULL)) s4_act_due
FROM temp_timeline
GROUP BY mkt_id, event_idTested, because you supplied create table and insert statements, thank you.
John
Maybe you are looking for
-
Feature Request: Consistently Intelligent Font Lists across all CS Program
Current Problems/Inconsistencies in Font Lists + Suggested Solutions: NUMBER OF FONTS SIMULTANEOUSLY DISPLAYED: Premiere Pro (PP): 16 (too few!) AE: 19 (too few!) Photoshop: 40 (adequate) Illustrator: auto-maximizing (displays as many fonts as screen
-
MacBook Pro 17" Glossy (Late 2011) vs MacBook Pro 13" Glossy (Late 2011)
Hi everybody, I have bought a MacBook Pro 17" 3 months ago. I really love it and it's cool. A few days ago, one of my friends came to my office, broght his MacBook Pro 13" which he had also bought it a few days after me. He told me he feels my MBP 17
-
Doubt on SAMPLE clause in SELECT statment
Hi all, I am having table with rows of 41. I issued a statement like this select * from TABLE_NAME SAMPLE(10); and it selected 3 rows (it is varying) . Everytime, i issued this statement, it is fetching different number of rows. Can anybody please ex
-
Link colors and formats not WYSIWYG
I'm having trouble with Link colors. I have the Link Format set to a certain colors but what I see after I publish my site is a crap shoot. Sometimes the change takes sometimes it doesn't, and often what I see in Safari 4/5 or Firefox is not the same
-
I Have and external disk in which I keep the exact copies of my cds, meaning 1444kbs sound files that ocupay a lot of space hence the external disk. I just bought a one tera Time Capsule to backup my macbook and this disc, I also woul like to back up