ROWS TO COLUMNS (9i and 10g)
Please help with the RowToCol function??
See: http://www.oracle.com/technology/oramag/code/tips2004/050304.html
I have been unable to get it to work on 9i - ORA-00904: "ROWTOCOL": invalid identifier.
Any ideas???
Thanks!
Example
STUDENT TEST1 TEST2 TEST3
TIM A
TIM B
TIM C
Desired Result
STUDENT TEST1 TEST2 TEST3
TIM A B C
Hi,
Did you create the RowToCol function in a schema (say scott) other than the one in which you're now trying to use it? If so, then you have to call it with the <owner_name>.<function_name>, like this:
scott.RowToCol (...)Most people create synonymns to avoid having to do this.
Either way, the user calling the function must have EXECUTE privileges on it. As the owner (e.g., scott), say something like:
GRANT EXECUTE ON RowToCol TO PUBLIC;As Tubby suggested, you may find STRAGG (or one of the pivot techniques) easier to use.
If that doesn't solve the problem, post a script that others (who have not already created the RowToCol function) can run and get the same error. That is, include the CREATE FUNCTION command in the script.
Similar Messages
-
Converting Rows into Column in Oracle 10g
Hi All,
I m using Oracle Version 10.1.0.2.0 - Production
I have requirement to convert rows into column wise as per the following:
My Query is:
WITH t
AS ( SELECT 'A' AS x, 100 AS y FROM DUAL
UNION ALL
SELECT 'B',200 FROM DUAL
SELECT X, Y
FROM t;
X Y
A 100
B 200
My Requirement is
A B
100 200
So any one could help me that how I resolve this.
Regards,
PrasantaDear frank,
Thanks for your support,.
It's working fine for static cases.If the first column is dynamic then how come i will resolve it.
Example:
Create table mytab (ID_C Varchar2(15),Value_N Number);
Records Population into MyTab table is dynamic.
Insert into mytab values('HO',5000);
Insert Into mytab values('PG1',2400);
Insert Into mytab values('PG2',3000);
Insert Into mytab values('PG3',800);
Commit;
SQL> Select * From MyTab;
IDC_ ValueN_
HO 5000
PG1 2400
PG2 3000
PG3 800
Then My expected result will be as follows
HO PG1 PG2 PG3
5000 2400 3000 800
Thanks and Regards,
Prasanta -
Row to column mapping and combining columns
Hi
I have one issue i want to concatenating some columns and map row as columns like below.I am giving one ex and have more than 1000 employees like this
Example
{Srno Eno Ename job datestart}
{1 01 jack------clerk------01-Jan-2008}
{ 2 01 jack-----snrclerk----01-Jun-2009}
{ 3 01 jack ---- officer------- 01-Jan-2010}
I want to display the row to columan mapping like first row concatenated as col2 and second row for col2 column etc
{eMpno------- col1 ------------------co12----------------------------------col3}
{0101 jackclerk 01-Jan-2008---jacksnrclerk01-Jun-2009------01jackofficer01-Jan-2010}
rgds
ramya
Edited by: user11243021 on Sep 7, 2010 5:21 AMwith t as (
select 1 srno,'01' eno,'jack' ename,'clerk' job,to_date('01-Jan-2008','dd-mon-yyyy') datestart from dual union all
select 2 srno,'01' eno,'jack' ename,'snrclerk' job,to_date('01-Jun-2009','dd-mon-yyyy') datestart from dual union all
select 3 srno,'01' eno,'jack' ename,'officer' job,to_date('01-Jan-2010','dd-mon-yyyy') datestart from dual
) -- end of data sample
select eno,
max(
case srno
when 1 then ename || ' ' || job || to_char(datestart,' dd-Mon-yyyy')
end
) col1,
max(
case srno
when 2 then ename || ' ' || job || to_char(datestart,' dd-Mon-yyyy')
end
) col2,
max(
case srno
when 3 then ename || ' ' || job || to_char(datestart,' dd-Mon-yyyy')
end
) col3
from t
group by eno
EN COL1 COL2 COL3
01 jack clerk 01-Jan-2008 jack snrclerk 01-Jun-2009 jack officer 01-Jan-2010
SQL> SY. -
Pivoting rows into columns in Oracle 10g
Hi,
I want to pivot rows into column in some optimal way.
I don't want to go with the DECODE option as the number of columns can be more than 200.
i have also tried the transpose logic which is making the pl/sql block too huge.
can i directly query the database for the desired output instead of storing the data into some arrays and displaying rows as columns?Hi,
Here's a dynamic way to do this is Oracle 10, using theSQL*Plus @ command to handle the dynamic parts.
First, let's see how we would do this using a static query:
WITH col_cntr AS
SELECT column_name
FROM all_tab_columns
WHERE owner = 'FKULASH'
AND table_name = 'TEST_EMP'
AND column_name NOT IN ('EMP_ID', 'TYPE_VAL')
, unpivoted_data AS
SELECT e.type_val
, c.column_name
, CASE c.column_name
WHEN 'X_AMT' THEN x_amt -- ***** Dynamic section 1 *****
WHEN 'Y_AMT' THEN y_amt -- ***** Dynamic section 1 *****
WHEN 'Z_AMT' THEN z_amt -- ***** Dynamic section 1 *****
END AS v
FROM test_emp e
CROSS JOIN col_cntr c
SELECT column_name AS type_val
, SUM (CASE WHEN type_val = 'Q1' THEN v ELSE 0 END) AS q1 -- ***** Dynamic section 2 *****
, SUM (CASE WHEN type_val = 'Q2' THEN v ELSE 0 END) AS q2 -- ***** Dynamic section 2 *****
, SUM (CASE WHEN type_val = 'Q3' THEN v ELSE 0 END) AS q3 -- ***** Dynamic section 2 *****
, SUM (CASE WHEN type_val = 'Q4' THEN v ELSE 0 END) AS q4 -- ***** Dynamic section 2 *****
FROM unpivoted_data
GROUP BY column_name
ORDER BY column_name
;Column names are hard-coded in two places:
(1) in the sub-query unpivoted_data, we had to know that there were 3 columns to be unpivoted, and that they were called x_amt, y_amt and z_amt. You want to derive all of that from all_tab_columns.
(2) in the main query, we had to know that there would be 4 pivoted columns in the rsult set, and that they would be called q1, q2, q3 and q4. You want to derive all that from the data actually in test_emp.
Instead of hard-coding those 2 dynamic sections, have Preliminary Queries write them for you, a split second before you run the main query, by running this script:
-- Before writing sub-scripts, turn off features designed for human readers
SET FEEDBACK OFF
SET PAGESIZE 0
PROMPT ***** Preliminary Query 1 *****
SPOOL c:\temp\sub_script_1.sql
SELECT ' WHEN '''
|| column_name
|| ''' THEN '
|| LOWER (column_name) AS txt
FROM all_tab_columns
WHERE owner = 'FKULASH'
AND table_name = 'TEST_EMP'
AND column_name NOT IN ('EMP_ID', 'TYPE_VAL')
ORDER BY column_name
SPOOL OFF
PROMPT ***** Preliminary Query 2 *****
SPOOL c:\temp\sub_script_2.sql
SELECT DISTINCT ', SUM (CASE WHEN type_val = '''
|| type_val
|| ''' THEN v ELSE 0 END) AS '
|| LOWER (type_val) AS txt
FROM test_emp
ORDER BY txt
SPOOL OFF
-- After writing sub-scripts, turn on features designed for human readers
SET FEEDBACK 5
SET PAGESIZE 50
-- Main Query:
WITH col_cntr AS
SELECT column_name
FROM all_tab_columns
WHERE owner = 'FKULASH'
AND table_name = 'TEST_EMP'
AND column_name NOT IN ('EMP_ID', 'TYPE_VAL')
, unpivoted_data AS
SELECT e.type_val
, c.column_name
, CASE c.column_name
@c:\temp\sub_script_1
END AS v
FROM test_emp e
CROSS JOIN col_cntr c
SELECT column_name AS type_val
@c:\temp\sub_script_2
FROM unpivoted_data
GROUP BY column_name
ORDER BY column_name
;As you can see, the main query looks exactly like the static query, except that the two dynamic sections have been replaced by sub-scripts. These 2 sub-scripts are written by 2 prelimiary queries, right before the main query.
As others have said, the fact that you're asking this question hints at a poor table design. Perhaps the table should be permanently stored in a form pretty much like unpivoted_data, above. When you need to display it with columns x_amt, y_amt, ..., then pivot it, using GROUP BY type_col. When you need to display it with columns q1, q2, ..., then pivot it using GROUP BY column_name. -
Hi all,
I have requirement to display the values in a single column base upon the empid
ex:
select * from emp where empid=1000
then actual result will come as
empid mgr dept sal
1000 10 10 1000
1000 20 20 2000
2000 10 10 1500
2000 20 20 3000but i want the result in the below format
for empid 1000 the result will show as
empid mgr dept sal mgr2 dept2 sal2
1000 10 10 1000 20 20 2000
2000 10 10 1500 20 20 3000Can anyone help me out to achieve this?
Cheers,
Sansomething like this
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1000 empid, 10 mgr, 10 dept, 1000 sal from dual union all
4 select 1000, 20, 20 , 2000 from dual union all
5 select 2000 ,10 , 10 , 1500 from dual union all
6 select 2000 ,20 , 20 ,3000 from dual
7 )
8 select empid,
9 max(decode(mgr,10,mgr)) mgr1,
10 max(decode(mgr,20,mgr)) mgr2,
11 max(decode(dept,10,dept)) dept1,
12 max(decode(dept,20,dept)) dept2,
13 max(decode(mgr,10,sal)) sal1,
14 max(decode(mgr,20,sal)) sal2
15 from t
16* group by empid
SQL> /
EMPID MGR1 MGR2 DEPT1 DEPT2 SAL1 SAL2
1000 10 20 10 20 1000 2000
2000 10 20 10 20 1500 3000 -
Need query to convert Single Row Multiple Columns To Multiple rows
Hi,
I have a table with single row like below
Column0 | Column1 | Column2 | Column3 | Column4|
Value0 | Value1 | Value2 | Value3 | Value4 |
Am looking for a query to convert above table data to multiple rows having column name and its value in each row as shown below
Column0 | Value0
Column1 | Value1
Column2 | Value2
Column3 | Value3
Column4 | Value4
Thanks in advance.
MohanHi ykMohan,
Dynamic UNPIVOT can be applied in this case as well.
CREATE TABLE dbo.T(ID INT,Column0 VARCHAR(99),Column1 VARCHAR(99),Column2 VARCHAR(99),Column3 VARCHAR(99),Column4 VARCHAR(99))
INSERT INTO T VALUES
(1,'Value0','Value1','Value2','Value3','Value4'),
(2,'Value0','Value1','Value2','Value3','Value4');
DECLARE @columns VARCHAR(MAX)
SELECT @columns=
STUFF(
SELECT ','+ COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='T' AND TABLE_SCHEMA='dbo' AND Column_name NOT IN('ID') FOR XML PATH('')
),1,1,'')
DECLARE @Sql NVARCHAR(MAX)
SET @Sql =
'SELECT ID, UPT.col,UPT.val FROM T
UNPIVOT
(val FOR col IN('+@columns+')) AS UPT'
EXEC sp_executeSQL @Sql
DROP TABLE T
If you have any feedback on our support, you can click
here.
Eric Zhang
TechNet Community Support -
Hello World ,
I want to make the below table data come in one row
Name | code | MARK
AAA | CODE2 | 50
AAA | CODE1 | 30
AAA | CODE3 | 22
BBB | CODE2 | 52
BBB | CODE3 | 53
CCC | CODE3 | 11
AES | CODE1 | 75
FES | CODE2 | 44
i want it to be like this
NAME | CODE1 | CODE2 | CODE3
AAA | 30 | 30 | 22
BBB | - | 52 | 53
CCC | - | - | 11
is there another way of DECODE?
RegardsA very small amount of effort on your side would have found the FAQ thread "How do I convert rows to columns" SQL and PL/SQL FAQ
-
Hello All,
I have a requirement where I have to convert rows to columns and vice versa in 10g.
Pivot isn't supported in 10g.
Actual query looks like this
change_name primary_key_id
ASSET 1501
COLLATERAL 1501
ASSET 1502
COLLATERAL 1510
ASSET 1503
COLLATERAL 1515
Required Output:
change_table_name Asset Collateral
Primary_key_id 1501 1501
Primary_key_id2 1502
Primary_key_id3 1510
Primary_key_id4 1503
Primary_key_id5 1515Thx
Shank.
Edited by: SamFisher on May 16, 2012 7:48 PMHi,
SamFisher wrote:
Hello All,
I have a requirement where I have to convert rows to columns and vice versa in 10g.
Pivot isn't supported in 10g.Pivot can be done in any version of Oracle.
The PIVOT keyword of the SELECT command isn't supported in Oracle 10. That's only one way of pivoting.
Actual query looks like this
change_name primary_key_id
ASSET 1501
COLLATERAL 1501
ASSET 1502
COLLATERAL 1510
ASSET 1503
COLLATERAL 1515
Required Output:
change_table_name Asset Collateral
Primary_key_id 1501 1501
Primary_key_id2 1502
Primary_key_id3 1510
Primary_key_id4 1503
Primary_key_id5 1515
I think you want something like this:
SELECT 'Primary_key_id
|| TO_CHAR ( NULLIF ( ROW_NUMBER () OVER (ORDER BY NVL ( a.primary_key_id
, c.primary_key_id
, 1
) AS change_table_name
, a.primary_key_id AS asset
, c.primary_key_id AS collateral
FROM table_x a
FULL OUTER JOIN table_x c ON a.primary_key_id = c.primary_key_id
-- Next 4 lines added after Ankit, below
AND a.change_name = 'ASSET'
AND c.change_name = 'COLLATERAL'
WHERE a.change_name = 'ASSET'
OR c.change_name = 'COLLATERAL'
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
This generates a unique change_table_name for each row. I don't see how you get the values you said you wanted associated with the other columns. That is, I have the same question as Justin:
Justin Cave wrote:
... How do you know that 1502 goes with primary_key_id2 and not primary_key_id3 or 4 or 1?Perhaps you don't really care which change_table_name is given to each row, just so long as they are unique, and numbered with consecutive integers (except for 1). If you really do need exactly what you posted, explain how you get it. You probably just need to change the analytic ORDER BY clause.
Edited by: Frank Kulash on May 17, 2012 6:56 AM
Corrected query -
Convert rows into columns nad vice versa in 10g
how to convert rows into columns in 10g??
Qwerty wrote:
see below for rows to column case
SQL> WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 select ltrim (sys_connect_by_path(test_string,','),',') test_string
9 from (
10 SELECT row_number() over(order by test_string) rno, test_string
11 FROM t)
12 WHERE connect_by_isleaf = 1 and rownum=1
13 connect by rno = prior rno+1;
TEST_STRING
AMERICA,HOLLYWOOD,US,WASHINGTONI hope you can do it for column to rows now.That's not really rows to columns. That's rows to a column, which is more commonly called string aggregation.
Rows to columns (or pivot) is more like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 --
9 select max(decode(rn,1,test_string)) as col_1
10 ,max(decode(rn,2,test_string)) as col_2
11 ,max(decode(rn,3,test_string)) as col_3
12 ,max(decode(rn,4,test_string)) as col_4
13* from (select test_string, row_number() over (order by test_string) as rn from t)
SQL> /
COL_1 COL_2 COL_3 COL_4
AMERICA HOLLYWOOD US WASHINGTON
SQL>And columns to rows (or unpivot) is like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select col_1 as col from t union all
7 select col_2 from t union all
8 select col_3 from t union all
9* select col_4 from t
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTONor...
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select decode(rownum,1,col_1,2,col_2,3,col_3,4,col_4) as col
7* from t, (select * from dual connect by rownum <= 4)
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTON
SQL> -
Transpose of columns to rows (unpivoting) and not rows to columns
Hi,
I am right now using oracle 10g. I HAVE the following specification. Here I specified only 5 columns.
We have upto 200 columns.
TRANS_ID PORTFILIO_NUM TICKER PRICE NUM_SHARES ........................................
2 100 MO 25.00 100 ........................................
3 100 MCD 31.50 100 ........................................
I want the above to be transformed into the following output .
TRANS_ID TYPE VALUE
2 PORTFILIO_NUM 100
2 TICKER MO
2 PRICE 25.00
2 NUM_SHARES 100.
I don't want to use case/decode function by hard coding the 200 columns.
Can anyone provide me a good way (mostly dynamic way) of doing this?
I searched the whole forum and also other forums. Everywhere I could find
rows to columns / columns to rows where the column names have been hardcoded.
I want a dynamic way of doing it. Let me know if u need any other inputs.
DDL :
CREATE TABLE PORT_TRANS
TRANS_ID VARCHAR2(100 BYTE),
PORTFILIO_NUM VARCHAR2(100 BYTE),
TICKER VARCHAR2(100 BYTE),
PRICE VARCHAR2(100 BYTE),
NUM_SHARES VARCHAR2(100 BYTE)
INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
VALUES('2','100','MO','25.00','100');
INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
VALUES('3,'100','MCD','31.50','100');
COMMIT;
Thanks,
Priya.Hi,
What you're trying to write is something like this:
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 4
SELECT p.trans_id
, CASE
WHEN c.n <= 2
THEN
CASE c.n
WHEN 1 THEN 'PORTFILIO_NUM'
WHEN 2 THEN 'TICKER'
END
ELSE
CASE c.n
WHEN 3 THEN 'PRICE'
WHEN 4 THEN 'NUM_SHARES'
END
END AS type
, CASE
WHEN c.n <= 2
THEN
CASE c.n
WHEN 1 THEN p.PORTFILIO_NUM
WHEN 2 THEN p.TICKER
END
ELSE
CASE c.n
WHEN 3 THEN p.PRICE
WHEN 4 THEN p.NUM_SHARES
END
END AS value
FROM port_trans p
CROSS JOIN cntr c
ORDER BY p.trans_id
, c.n
;I wrote this as if CASE could only handle 2 choices, rather than 128, just to show how to nest CASE expressions.
What you have to do is write the CASE expressions, based on the contents of all_tab_columns.
In your sample data, all of the columns are VARCHAR2 (another design flaw). If you have any columns of other types, use TO_CHAR to convert them to VARCHAR2; that is, the final code to be run will have something like:
... WHEN 4 THEN TO_CHAR (p.NUM_SHARES)If I had to do this, I might run several queries on all_tab_columns, each producing one script, containing just a fragment of the query.
To run the whole thing, I would hard-code a main query like this
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <=
@num_columns.sql
SELECT p.trans_id
, CASE
@type.sql
END AS type
, CASE
@value.sql
END AS value
FROM port_trans p
CROSS JOIN cntr c
ORDER BY p.trans_id
, c.n
;As with any coidng, start small and take baby steps. Maybe the first step would just be to write num_columns.sql, which just contains the number 4. When you can do that, hard-code the CONNECT BY query, calling num_columns.sql.
Good luck! -
Dynamic rows to columns oracle 10g
Hi,
I'm using oracle 10g. I have a requiriement where I need to show rows to columns. I have read through many posts but I couldn't find what I wanted to solve. Lots of them are using decode, since they know the values in one column.
My table has name, value and date. I need to get values for each name at certain date (each distinct date needs to become column). I don't know the name beforehand.
Name, Value, Date
T1 100 06-27-2011 09:00:00
T2 100 06-27-2011 09:00:00
T1 200 06-27-2011 09:15:00
T2 150 06-27-2011 09:15:00
I would also need to use a date range. Someone can request date between 09:00:00 and 09:05:00 or 09:00:00 and 09:30:00 etc.
I need to print
Name, 06-27-2011 09:00:00, 06-27-2011 09:15:00
T1 100 200
T2 100 150
Appreciate any advice on this.
Edited by: user8801143 on 28-Jun-2011 08:23With 10g
see http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740#2989343200346664698
search for post on February 11, 2011 and reply on February 14, 2011
with 11g see the pivot clause -
Interactive Report Column Headings and Row Height
I am using the div style="width:350px;" method to control the width of columns in various interactive reports. That works fine except for the following:
1. When creating filters, the <div...> stuff shows up along with the actual column heading, thus confusing some end users
2. Even when I uncheck the "Use same text for single row view" checkbox and then provide a simple single row view label, the <div> stuff still shows up on the single row view
Does anyone have a better solution?
Also, does anyone know of a way to limit the row height within an interactive report row? I have some columns of data that contain a large amount of HTML data and I'd like to be able to limit the number of rows that show on the report.
Is Oracle planning to provide some better control over the Interactive Report columns in another version? The Interactive Report is such a huge improvement in usability in APEX - it would be great to take it to another level by providing some better control over column width and row height.
Edited by: DaleB on Jun 18, 2009 8:54 AM
Edited by: DaleB on Jun 18, 2009 8:54 AMDale,
Unfortunately we don't have much we can use to do what you would like. I would have said it's impossible until version 4 but you could actually do something similar to what Roel has done. His trick is in the edit button. He changed the edit button to use an "onload" call to a JavaScript process. You could do the same but call a process that goes across the rows and styles each column. Now because you don't have a way to identify the column (can't use the order because the end user could change it) you'll have to write the code to look at the top row first and then style the appropriate column. As far as I can tell, this would be quite difficult and inefficient. Having said that if you need it that bad and would like some help with it, put up an example application on apex.oracle.com and provide the workspace/username/password and I'll take a look.
Regards,
Dan
http://danielmcghan.us
http://sourceforge.net/projects/tapigen
You can reward this reply by marking it as either Helpful or Correct ;-) -
Hi
I have folowing scenario. I am getting the result with some query like below :
STATE DAY AVG
NY 02/02 5
NY 02/03 10
NY 02/04 20
NY 02/05 15
IL 02/02 23
IL 02/03 34
IL 02/04 29
IL 02/05 9
FL 02/02 15
FL 02/03 8
FL 02/04 9
FL 02/05 10
and so on..Now I want to convert it from rows to column, but still want to keep STATE column group by :
so the result would be :
STATE 02/02 02/03 02/04 02/05
NY 5 10 20 15
IL 23 34 29 9
FL 15 8 9 10
and so on...I tried using pivot function, but it didnt work. is it even possible? or I will have to do it in code (.net c#) side.
Thanks1 WITH t AS (
2 SELECT 'NY' state,'02/02' mydt,5 myavg FROM dual
3 UNION all
4 SELECT 'NY','02/03',10 FROM dual
5 UNION all
6 SELECT 'NY','02/04',20 FROM dual
7 UNION all
8 SELECT 'NY','02/05',15 FROM dual
9 UNION all
10 SELECT 'IL','02/02',23 FROM dual
11 UNION all
12 SELECT 'IL','02/03',34 FROM dual
13 UNION all
14 SELECT 'IL','02/04',29 FROM dual
15 UNION all
16 SELECT 'IL','02/05',9 FROM dual
17 UNION all
18 SELECT 'FL','02/02',15 FROM dual
19 UNION all
20 SELECT 'FL','02/03',8 FROM dual
21 UNION all
22 SELECT 'FL','02/04',9 FROM dual
23 UNION all
24 SELECT 'FL','02/05',10 FROM dual
25 )
26 SELECT * FROM t
27 PIVOT
28 (
29 SUM(myavg)
30 FOR mydt IN('02/02','02/03','02/04','02/05')
31 )
32* ORDER BY state DESC
SQL> /
ST '02/02' '02/03' '02/04' '02/05'
NY 5 10 20 15
IL 23 34 29 9
FL 15 8 9 10Am I missing some thing here ? -
How do I get the Layout Guides (A,B,C column headers and 1,2,3 Row Headers) to print on my spreadsheet? They are invaluable for discussing the data with my clients over the phone.
They appear while I am editing, but don't print with the spreadsheet. I know how to do it in Excel, but I am transitioning to Numbers. I can't imagine I have to type them into their own columns and rows. It must be a difference in vernacular that I can't find the solution in the User Guide. Can anyone help?Hi ktjobauer,
Numbers is not Excel and Excel is not Numbers. Numbers is WYSIWYG (at least in File > Print and the actual printout).
I can't imagine I have to type them into their own columns and rows.
No, you don't. You can use the charm of Numbers to create cell references for your Excel clients.
In this Numbers Table, I have added some extra Columns that you can hide later.
Column B =COLUMN(A2)
Column C =HLOOKUP(B2,'Table 1-1' :: $1:$2,2,FALSE) [explanation later]
Column D =ROW(B2)
Column E =C2&D2
Add those formulas to the first Body Row (below the Header Row) and Fill Down.
Column C refers to another Table which you need only create once, to convert a Column number to a letter:
and so on from 1-26, A-Z.
You can move the second Table to another Sheet to hide it. Formulas will automatically adjust to keep the links between Sheets.
Now in the first Table, select and Hide Columns B,C,D. Formulas will continue to work with hidden cells:
Regards,
Ian. -
Convert rows to columns and put line break in between using t-sql
Hi,
I have a table with 5 columns..and my source data looks like this..
RecordID ID Display AddressType EmailAddress
1 1 GeneratedBy From
[email protected]
1 1 ReceivedBy To
[email protected]
1 1 ReceivedBy To
[email protected]
2 1
3 1 GeneratedBy From
[email protected]
3 1 GeneratedBy From [email protected]
3 1 ReceivedBy To
[email protected]
I need t-sql to show output as..
RecordID ID FullDisplay
1 1 GeneratedBy From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected] ; To -
[email protected]
2 1 Null
3 1 GeneratedBy From -
[email protected] ; From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected]
Display field will have 3 values - "GeneratedBy" , "ReceivedBy" or Null
AddresType field will have 3 values - "From" , "To" and Null.
In the above example, Those 7 records belongs to ID=1.
Whenever RecordID is same I want to show everything in one line with line breaks in between.
In the above example RecordID=1 has 3 rows, display it as 1 row. But Whenever 'ReceivedBy' is there for same recordID put a line break before "ReceivedBy"
create Statement:
Create Table SampleTest
(RecordID int null, ID int null , Dispplay varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
Thanks!
sqlTry below
drop table SampleTest
GO
Create Table SampleTest
(RecordID int null, ID int null , Display varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
--Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
with CTE1 as
select ROW_NUMBER() over(PARTITION by RecordID ,ID,Display order by EmailAddress)rno,* From SampleTest
), CTE2 as (
select RecordID ,ID,'GeneratedBy '+ STUFF(( SELECT '; From - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'GeneratedBy'
FOR XML PATH('')
), 1, 2, '' ) GeneratedBy,
'ReceivedBy '+ STUFF(( SELECT '; To - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'ReceivedBy'
FOR XML PATH('')
), 1, 2, '' ) ReceivedBy
From CTE1 a
group by RecordID ,ID
select RecordID ,ID,GeneratedBy +CHAR(13)+ ReceivedBy as FullDisplay from CTE2
Thanks
Saravana Kumar C
Maybe you are looking for
-
Problem with Iphone and telephone provider
In October last year I bought Iphone 4 in T com Croatia. In the beggining of October 2012 Iphone 4 had a problem with charging. It says charging, but nothing happened. I gave Iphone to telephone provider in order to send it on service because of warr
-
Data upload for vendor balances using BDC
hi abap experts, I have a requirement on data uploading using BDC. For the vendor balances ie. for transaction FBL1N ( I was given a template for vendor balance upload and need to write a BDC program for that ) I need upload the exsisting transactio
-
Uploading Large csv file from Local File
I have a 6GB csv file which I created on my local machine which is named TrainDF.csv. I can't upload it directly as it exceeds the 1.95GB size limit uncompressed. However, I tried saving it as an RData file (as well as a zip file of the RData file)
-
Latest Adobe Acrobat X doesn't support PNG transparent graphic?
So in the past using version 8.x I had no problem inserting graphics, including a signature that is a transparent PNG. Now with the update to the latest studio 5.5 which came with Acrobat X 10.1.1 when trying to insert that graphic (which took a whi
-
A very disturbing Safari 6 problem when downloading files
After downloading a file from Hubspot.com, this is what I see when clicking on the Show Downloads button on Safari 6. This is actually the third time it's happened. I did a clean install of OS X 10.8 to see if the problem would go away. Sadly, it did