Return Columns as Rows
Dear All
I have the following query:
SELECT DISTINCT
Teacher.TeacherSurname + ', ' + Teacher.TeacherForename + ' (' + Teacher.TeacherTitle + ')' AS 'TeachersFullname',
AdditionalTeacher1.TeacherSurname + ', ' + AdditionalTeacher1.TeacherForename + ' (' + AdditionalTeacher1.TeacherTitle + ')' AS 'AdditionalTeacher1Fullname',
AdditionalTeacher2.TeacherSurname + ', ' + AdditionalTeacher2.TeacherForename + ' (' + AdditionalTeacher2.TeacherTitle + ')' AS 'AdditionalTeacher2Fullname',
AdditionalTeacher3.TeacherSurname + ', ' + AdditionalTeacher3.TeacherForename + ' (' + AdditionalTeacher3.TeacherTitle + ')' AS 'AdditionalTeacher3Fullname',
(SELECT 1
FROM dbo.SENAlertHistory
WHERE SENAlertHistory.SENAlertHistoryTeacherCode = Teacher.TeacherCode
AND SENAlertHistory.SENAlertHistorySENAlertID = SENAlert.SENAlertID) AS 'AlertRead'
FROM dbo.Class
INNER JOIN dbo.Teacher
ON Class.ClassTeacherCode = Teacher.TeacherCode
INNER JOIN dbo.ClassMember
ON ClassMember.ClassMemberClassCode = Class.ClassClassCode
CROSS JOIN dbo.SENAlert
INNER JOIN dbo.Student
ON SENAlert.SENAlertStudentID = Student.StudentID
AND Student.StudentID = ClassMember.ClassMemberStudentID
LEFT OUTER JOIN dbo.Teacher AdditionalTeacher1
ON AdditionalTeacher1.TeacherCode = Class.ClassAdditionalTeacherCode1
LEFT OUTER JOIN dbo.Teacher AdditionalTeacher2
ON AdditionalTeacher2.TeacherCode = Class.ClassAdditionalTeacherCode2
LEFT OUTER JOIN dbo.Teacher AdditionalTeacher3
ON AdditionalTeacher3.TeacherUsername = Class.ClassAdditionalTeacherCode3
LEFT OUTER JOIN dbo.SENAlertHistory
ON SENAlertHistory.SENAlertHistoryTeacherCode = Teacher.TeacherCode
AND SENAlertHistory.SENAlertHistorySENAlertID = SENAlert.SENAlertID
AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher1.TeacherCode
AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher2.TeacherCode
AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher3.TeacherCode
WHERE SENAlert.SENAlertID = 15
ORDER BY TeachersFullname
The results that it is producing look as follows:
However, what I am trying to do is return a list with just two columns: TeachersFullname and AlertRead. I would like the AdditionalTeacher1, 2 and 3 columns to become a continuation of the TeachersFullname column with their own respective AlertRead counts.
So in the above example, 'Lowe' will become another teacher listed in the first column with a count of his unread alerts.
Ideally I would like the TeachersFullname column to be distinct so that teachers only appear once.
I have looked into PIVOT and using JOIN but haven't been able to work out how to do this. I would really appreciate any advice you may be able to give.
Many thanks
Daniel
PS, in case it helps to put things into perspective, here is the database
diagram (not a diagram of the query itself)
Hi djs25uk,
Thank you for your question. I am currently looking into this issue and will give you an update as soon as possible.
Thank you for your understanding and support.
If you have any feedback on our support, please click
here.
Elvis Long
TechNet Community Support
Similar Messages
-
Can i search multiple sheets in a document for text in column a to return the entire row if column a matches in a
separate sheet?Thank you, Barry. That was helpful, and am hopeful that what I want to do is possible.
I am creating a spreadsheet that currently has 20 sheets, of which certain sheets have more than one table. I will be adding more sheets. I would like to return results for all occurences of the search string. Preferably into a seperate spreadsheet. It would be perfect if that seperate sheet updated whenever I update information in the first spreadsheet. To give an example:
Sheet: baskets
Tables: straw
wire
Sheet: barware
Tables: glasses
decanters
coasters
My tables all have the same titiels:
Vendor Description Cost Selling Price
Since I will have upwards of 100 sheets, with multiple tables, and most of my vendors will fit into multiple sheet categories, it would be helpful if I could also see what my order will be from each vendor, not just who I will be ordering each item from. How would I do that?
I hope I conveyed that properly.
Thank you in advance for your help,
Rana -
How to get the current selected column and row
Hi,
A difficult one, how do i know which column (and row would also be nice) of a JTable is selected?
e.g.
I have a JButton which is called "Edit" when i select a cell in the JTable and click the button "Edit" a new window must be visible as a form where the user can edit the a part of a row.
Then the column which was selected in the JTable must be given (so i need to know current column) and then i want the TextField (the one needed to be edited) be active with requestFocus(). So it would be
pricetextfield.requestFocus();
Problem now is that i have to click every time in the window the JTextField which was selected in the JTable. I have chosen for this way of editing because my application is multi-user and it would be too difficult for me when everybody did editing directly (catch signals, reload data, etc.).
My question is how do I know the current column and the current row in a JTable?I'm not sure what your mean by the "current" row or column, but the following utility methods return
which row and column have focus within the JTable.
public static int getFocusRow(JTable table) {
return table.getSelectionModel().getLeadSelectionIndex();
public static int getFocusColumn(JTable table) {
return table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
} -
How to return the entire row from a table
Hi guys,
Tabl A
FirstName varchar2(10),
Age Number,
Add varchar2(100),
Table B
Filedname varchar2(200), -- contains all the fields of table A
Datatype varchar2(100), -- Contains the datatypes of the filedname
Length Number -- contains the length of the fileds
Now how can i return the entire row from table A with the datatype and its length.
Any help would be appreciated ?
Here is the query I wrote but it how to take the datatype and its length..
create or replace procedure disp_table_data
as
type r_cursor is REF CURSOR;
c_A r_cursor;
er A%rowtype;
begin
open c_A for select * from A;
loop
fetch c_A into er;
exit when c_A%notfound;
dbms_output.put_line(er.FirstName||'--'||er.Age);
end loop;
close c_A;
END;
/Guys,
I want column value from table A and its corresponding data_type and length from table B. I think I cant do it through joins.
Any idea would be appreciated ?.
Example ..
Tabl A
FirstName varchar2(10),
Age Number,
Add varchar2(100)
insert into A values('John',24,'Boston');
Table B
Filedname varchar2(200), -- contains all the fields of table A
Datatype varchar2(100), -- Contains the datatypes of the filedname
Length Number -- contains the length of the fileds
insert into B values('FirstName','varchar2',10); -- this is coming from table A.
Output should be like this...
John,Varchar2,10
Here (John is the FirstName - coming from table A, Varchar2 is a Datatype and 10 is the Length which are coming from table B ). Only column values are coming from table A , corresponding datatype and length are coming from B.
Any idea would be appreciated ?
Thanks. -
Convert columns to row equivalent to stragg function in oracle sql
Hi,
Sorry i forgot my Oracle version :
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
I looking for a function in discoverer equivalent to stragg sql function.
Note : stragg function convert columns to rows.
Thanks
SELECT deptno, stragg ('-' || ename)
FROM emp_test
GROUP BY deptno;
DEPTNO STRAGG_STR
10 -CLARK-KING-MILLER
20 -SMITH-FORD-ADAMS-SCOTT-JONES
30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD
3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32Hi again,
*1- I created my function in my schema.*
CREATE OR REPLACE TYPE t_string_agg AS OBJECT
g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER
SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER IS
BEGIN
sctx := t_string_agg(NULL);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER IS
BEGIN
SELF.g_string := self.g_string || ',' || value;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER IS
BEGIN
SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
RETURN ODCIConst.Success;
END;
END;
SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
SHOW ERRORS
*2- I ran my query in my schema with sqlplus.*
SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
FROM emp_test
order by deptno;
DEPTNO ENAME SAL EMPLOYEES
10 CLARK 2450 CLARK,KING,MILLER
10 KING 5000 CLARK,KING,MILLER
10 MILLER 1300 CLARK,KING,MILLER
20 JONES 2975 JONES,FORD,ADAMS,SMITH,SCOTT
20 FORD 3000 JONES,FORD,ADAMS,SMITH,SCOTT
20 ADAMS 1100 JONES,FORD,ADAMS,SMITH,SCOTT
20 SMITH 800 JONES,FORD,ADAMS,SMITH,SCOTT
20 SCOTT 3000 JONES,FORD,ADAMS,SMITH,SCOTT
30 WARD 1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 TURNER 1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 ALLEN 1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 JAMES 950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 BLAKE 2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
30 MARTIN 1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN
14 rows selected.
*3- I import this function in discoverer administration*
4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
Any ideas.
Thank in advance.
Regards Salim. -
Calling a PL/SQL function returning Netsed Table Rows
Hi,
I am trying to call a Function which returns Nested Table rows (as Out Parameter) in Java .
When I am trying to use
pstmt.registerOutParameter(3, OracleTypes.OTHER);
to capture the Out parameter in Java code , I get the follwoing error :
java.sql.SQLException: Invalid column type
I have even tried using OracleTypes.JAVA_OBJECT ,but I get the same error.
If I use OracleTypes.JAVA_STRUCT I get
java.sql.SQLException: Parameter Type Conflict: sqlType=2008
error.
Please help .
Am I doing the right thing ?
Thanks in advance.
Ninadhttp://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/jdbc20/jdbc20.html
-
One column one row w/ separator to be hierarchical columns
Dear Gurus,
I want to present the "+one column/one row data+"
F:\JDeveloper\Tut\TIJ4-code\generics\watercolors\Watercolors.javaas this follow:
id parent_id
Watercolors.java watercolors
watercolors generics
generics TIJ4-code
TIJ4-code Tut
Tut JDeveloper
JDeveloper F:Id better using an sql rather than pl/sql.
regards,I think you'd struggle to do this in SQL alone, unless you use some fancy MODEL clause or Michaels can come up with some nifty XML solution. I would probably go with some PL/SQL as a pipelined function...
SQL> create table treedata as
2 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Adding Window Event Listener. Working with MDI.swf' as cp from dual union all
3 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating Finger Icon.swf' from dual union all
4 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating Key Icon.swf' from dual union all
5 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class Containing Information on Fingers.swf' from dual union all
6 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class Handling Shift Press.swf' from dual union all
7 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class KBLayout\Creating the Class KBLayout (Part 1).swf' from dual union all
8 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class KBLayout\Creating the Class KBLayout (Part 2).swf' from dual union all
9 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class KeyCode.swf' from dual union all
10 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class KeyIcon\Creating the Class KeyIcon (Part 1).swf' from dual union all
11 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class KeyIcon\Creating the Class KeyIcon (Part 2).swf' from dual union all
12 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class for Key Systemization .swf' from dual union all
13 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating Supplementary Classes\Creating the Class for Saving Information on Keys.swf' from dual union all
14 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Creating the Main Window (the Class MainWindow).swf' from dual union all
15 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Class Constructor.swf' from dual union all
16 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Creating Methods Responsible for Icon Fill.swf' from dual union all
17 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Creating Methods Responsible for Icon Highlight\Creating Methods Responsible for Icon Highlight (Part 1).swf' from dual union all
18 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Creating Methods Responsible for Icon Highlight\Creating Methods Responsible for Icon Highlight (Part 2).swf' from dual union all
19 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Defining Some Static Variables\Defining Some Static Variables (Part 1).swf' from dual union all
20 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Defining Some Static Variables\Defining Some Static Variables (Part 2).swf' from dual union all
21 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Highlighting Icons.swf' from dual union all
22 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Overriding the Method run.swf' from dual union all
23 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Overriding the Method setVisible.swf' from dual union all
24 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\Registering Keyboard in the Main Window of Application .swf' from dual union all
25 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\KeyboardGUI\The Methods new_icon and new_fingericon.swf' from dual union all
26 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Adding Keyboard Listener to the Application.swf' from dual union all
27 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Creating Methods to Test the Efficiency of the User''s work.swf' from dual union all
28 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Creating the class ExerciseGUI.swf' from dual union all
29 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Creating the class Lessons and Working with It in the Class ExerciseGUI.swf' from dual union all
30 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Handling Pressed Keys.swf' from dual union all
31 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Improving Graphical Interface of the Class ExerciseGUI.swf' from dual union all
32 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Setting Position and the Sizes of the Main Window.swf' from dual union all
33 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Statistics.swf' from dual union all
34 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Working with Graphical Interface of the Class ExerciseGUI.swf' from dual union all
35 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\The Class ExerciseGUI\Working with Keyboard Events.swf' from dual union all
36 select 'F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\Working with Main Window Menu. Positioning the Main Window.swf' from dual
37 /
Table created.
SQL>
SQL>
SQL>
SQL> CREATE OR REPLACE TYPE pth IS TABLE OF VARCHAR2(32767);
2 /
Type created.
SQL>
SQL> CREATE OR REPLACE FUNCTION tree RETURN pth PIPELINED IS
2 l_maxlen NUMBER;
3 l_parent_path VARCHAR2(255);
4 type t_output is table of varchar2(32767) index by pls_integer;
5 l_output t_output;
6 l_cnt NUMBER := 0;
7 PROCEDURE show_children(p_path IN VARCHAR2, p_lvl IN NUMBER, p_tree IN VARCHAR2) IS
8 l_ch_path_cnt number;
9 CURSOR cur_children_elements IS -- non path children
10 select replace(cp,p_path) as ch
11 from treedata
12 where instr(replace(cp,p_path),'\') = 0
13 order by 1;
14 CURSOR cur_children_paths IS -- path children
15 select pth
16 ,row_number() over (order by pth) as rn
17 ,count(*) over () as cnt
18 from (
19 select distinct substr(replace(cp,p_path),1,instr(replace(cp,p_path),'\')) as pth
20 from treedata
21 where instr(cp,p_path) > 0
22 and instr(replace(cp,p_path),'\') > 0
23 order by 1
24 );
25 BEGIN
26 select count(*)
27 into l_ch_path_cnt
28 from treedata
29 where instr(cp,p_path) > 0
30 and instr(replace(cp,p_path),'\') > 0;
31 for c in cur_children_elements
32 loop
33 l_cnt := l_cnt + 1;
34 if l_ch_path_cnt = 0 then
35 l_output(l_cnt) := replace(replace(substr(p_tree,1,length(p_tree)-2)||' ','+',' '),'-',' ')||' '||c.ch;
36 else
37 l_output(l_cnt) := replace(replace(p_tree,'+',' '),'-',' ')||' '||c.ch;
38 end if;
39 end loop;
40 if l_ch_path_cnt = 0 then
41 l_cnt := l_cnt + 1;
42 l_output(l_cnt) := substr(p_tree,1,length(p_tree)-2);
43 else
44 l_cnt := l_cnt + 1;
45 l_output(l_cnt) := p_tree;
46 end if;
47 for p in cur_children_paths
48 loop
49 if p.rn != p.cnt then
50 l_cnt := l_cnt + 1;
51 l_output(l_cnt) := substr(p_tree,1,length(p_tree)-2)||'+-'||substr(p.pth,1,length(p.pth)-1);
52 show_children(p_path||p.pth, p_lvl+1, substr(p_tree,1,length(p_tree)-2)||'| | ');
53 else
54 l_cnt := l_cnt + 1;
55 l_output(l_cnt) := substr(p_tree,1,length(p_tree)-2)||'\-'||substr(p.pth,1,length(p.pth)-1);
56 show_children(p_path||p.pth, p_lvl+1, substr(p_tree,1,length(p_tree)-2)||' ');
57 end if;
58 end loop;
59 END;
60 BEGIN
61 -- first display the common parent path
62 select max(length(txt)) as max_ln
63 into l_maxlen
64 from (
65 select substr(cp,1,rn) as txt
66 from treedata, (select rownum rn from dual connect by rownum <= 255)
67 group by substr(cp,1,rn)
68 having count(*) = (select count(*) from treedata)
69 );
70 select substr(cp,1,l_maxlen)
71 into l_parent_path
72 from treedata
73 where rownum = 1;
74 PIPE ROW(l_parent_path);
75 -- now recurse the data
76 show_children(l_parent_path, 1, '| ');
77 for i IN 1..l_cnt
78 loop
79 PIPE ROW(l_output(i));
80 end loop;
81 RETURN;
82 END tree;
83 /
Function created.
SQL>
SQL> select * from table(tree);
COLUMN_VALUE
F:\Teach_Pro_JAVA\Teach_Pro_JAVA\Teachpro\Working Over the Project\
| Adding Window Event Listener. Working with MDI.swf
| Creating the Main Window (the Class MainWindow).swf
| Working with Main Window Menu. Positioning the Main Window.swf
|
+-Creating Supplementary Classes
| | Creating Finger Icon.swf
| | Creating Key Icon.swf
| | Creating the Class Containing Information on Fingers.swf
| | Creating the Class Handling Shift Press.swf
| | Creating the Class KeyCode.swf
| | Creating the Class for Key Systemization .swf
| | Creating the Class for Saving Information on Keys.swf
| |
| +-Creating the Class KBLayout
| | Creating the Class KBLayout (Part 1).swf
| | Creating the Class KBLayout (Part 2).swf
| |
| \-Creating the Class KeyIcon
| Creating the Class KeyIcon (Part 1).swf
| Creating the Class KeyIcon (Part 2).swf
|
+-KeyboardGUI
| | Class Constructor.swf
| | Creating Methods Responsible for Icon Fill.swf
| | Highlighting Icons.swf
| | Overriding the Method run.swf
| | Overriding the Method setVisible.swf
| | Registering Keyboard in the Main Window of Application .swf
| | The Methods new_icon and new_fingericon.swf
| |
| +-Creating Methods Responsible for Icon Highlight
| | Creating Methods Responsible for Icon Highlight (Part 1).swf
| | Creating Methods Responsible for Icon Highlight (Part 2).swf
| |
| \-Defining Some Static Variables
| Defining Some Static Variables (Part 1).swf
| Defining Some Static Variables (Part 2).swf
|
\-The Class ExerciseGUI
Adding Keyboard Listener to the Application.swf
Creating Methods to Test the Efficiency of the User's work.swf
Creating the class ExerciseGUI.swf
Creating the class Lessons and Working with It in the Class ExerciseGUI.swf
Handling Pressed Keys.swf
Improving Graphical Interface of the Class ExerciseGUI.swf
Setting Position and the Sizes of the Main Window.swf
Statistics.swf
Working with Graphical Interface of the Class ExerciseGUI.swf
Working with Keyboard Events.swf
51 rows selected.
SQL> -
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 -
XMLTABLE returns only first row
I have follwoing XML inserted into the column named as TEXT in the table MASTERTB.
*<?xml version="1.0" encoding="utf-8" ?>*
*<Rowsets DateCreated="2010-11-30T11:12:10" EndDate="2010-06-05T16:52:23" StartDate="2010-06-05T16:52:23" Version="12.0.10 Build(18)">*
*<Rowset>*
*<Columns>*
*<Column Description="Material Number" MaxRange="1" MinRange="0" Name="MATERIAL" SQLDataType="1" SourceColumn="MATERIAL"/>*
*<Column Description="" MaxRange="1" MinRange="0" Name="TANK" SQLDataType="1" SourceColumn="TANK"/>*
*</Columns>*
*<Row>*
*<MATERIAL>1000000144</MATERIAL>*
*<TANK>T1000</TANK>*
*</Row>*
*<Row>*
*<MATERIAL>2000000008</MATERIAL>*
*<TANK>T1000</TANK>*
*</Row>*
*<Row>*
*<MATERIAL>2000000009</MATERIAL>*
*<TANK>T1000</TANK>*
*</Row>*
*<Row>*
*<MATERIAL>2000000016</MATERIAL>*
*<TANK>T1000</TANK>*
*</Row>*
*<Row>*
*<MATERIAL>3000000036</MATERIAL>*
*<TANK>T1000</TANK>*
*</Row>*
*</Rowset>*
*</Rowsets>*
Now, when my requirement is to get all the Material values so when I run follwoing query in Oracle,
SELECT RW.MATERIAL
FROM MASTERTB TM,
XMLTable('//Row' PASSING TM.TEXT
COLUMNS "MATERIAL" CHAR(30) PATH 'MATERIAL') AS RW
it return only 1000000144 (First MATERIAL). How can I read all the MATERIAL? Also, how can I read the entire XML in Text format if I want to check what has been inserted?
ANy help will be appreciated !
Edited by: 967327 on Oct 27, 2012 12:28 AM>
<Rowsets DateCreated="2010-11-30T11:12:10" EndDate="2010-06-05T16:52:23" StartDate="2010-06-05T16:52:23" Version="12.0.10 Build(18)">
<Rowset>
</Rowset>
>
so where is </Rowsets> ?
your query works for me
SQL> select * from v$version where rownum=1;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
SQL>
SQL> with MASTERTB as
2 (select
3 xmltype('<?xml version="1.0" encoding="utf-8" ?>
4 <Rowsets DateCreated="2010-11-30T11:12:10" EndDate="2010-06-05T16:52:23" StartDate="2010-06-05T16:52:23" Version="12.0.10 Build(18)">
5 <Rowset>
6 <Columns>
7 <Column Description="Material Number" MaxRange="1" MinRange="0" Name="MATERIAL" SQLDataType="1" SourceColumn="MATERIAL"/>
8 <Column Description="" MaxRange="1" MinRange="0" Name="TANK" SQLDataType="1" SourceColumn="TANK"/>
9 </Columns>
10 <Row>
11 <MATERIAL>1000000144</MATERIAL>
12 <TANK>T1000</TANK>
13 </Row>
14 <Row>
15 <MATERIAL>2000000008</MATERIAL>
16 <TANK>T1000</TANK>
17 </Row>
18 <Row>
19 <MATERIAL>2000000009</MATERIAL>
20 <TANK>T1000</TANK>
21 </Row>
22 <Row>
23 <MATERIAL>2000000016</MATERIAL>
24 <TANK>T1000</TANK>
25 </Row>
26 <Row>
27 <MATERIAL>3000000036</MATERIAL>
28 <TANK>T1000</TANK>
29 </Row>
30 </Rowset></Rowsets>') TEXT from dual)
31 SELECT RW.MATERIAL
32 FROM MASTERTB TM,
33 XMLTable('//Row' PASSING TM.TEXT
34 COLUMNS "MATERIAL" CHAR(30) PATH 'MATERIAL') AS RW
35 /
MATERIAL
1000000144
2000000008
2000000009
2000000016
3000000036
SQL>
SQL> select * from v$version where rownum=1;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL>
SQL> with MASTERTB as
2 (select
3 xmltype('<?xml version="1.0" encoding="utf-8" ?>
4 <Rowsets DateCreated="2010-11-30T11:12:10" EndDate="2010-06-05T16:52:23" StartDate="2010-06-05T16:52:23" Version="12.0.10 Build(18)">
5 <Rowset>
6 <Columns>
7 <Column Description="Material Number" MaxRange="1" MinRange="0" Name="MATERIAL" SQLDataType="1" SourceColumn="MATERIAL"/>
8 <Column Description="" MaxRange="1" MinRange="0" Name="TANK" SQLDataType="1" SourceColumn="TANK"/>
9 </Columns>
10 <Row>
11 <MATERIAL>1000000144</MATERIAL>
12 <TANK>T1000</TANK>
13 </Row>
14 <Row>
15 <MATERIAL>2000000008</MATERIAL>
16 <TANK>T1000</TANK>
17 </Row>
18 <Row>
19 <MATERIAL>2000000009</MATERIAL>
20 <TANK>T1000</TANK>
21 </Row>
22 <Row>
23 <MATERIAL>2000000016</MATERIAL>
24 <TANK>T1000</TANK>
25 </Row>
26 <Row>
27 <MATERIAL>3000000036</MATERIAL>
28 <TANK>T1000</TANK>
29 </Row>
30 </Rowset></Rowsets>') TEXT from dual)
31 SELECT RW.MATERIAL
32 FROM MASTERTB TM,
33 XMLTable('//Row' PASSING TM.TEXT
34 COLUMNS "MATERIAL" CHAR(30) PATH 'MATERIAL') AS RW
35 /
MATERIAL
1000000144
2000000008
2000000009
2000000016
3000000036
SQL> try
31 SELECT RW.MATERIAL
32 FROM MASTERTB TM,
33 XMLTable('Rowsets/Rowset/Row' PASSING TM.TEXT
34 COLUMNS "MATERIAL" varchar2(30) PATH 'MATERIAL') AS RW
35 /
MATERIAL
1000000144
2000000008
2000000009
2000000016
3000000036
SQL> -
Is there a chance to change data from row to column and vice versa just by a click. Need to have the data of the rows in horizontal view in the table.
Badunit wrote:
Yvan has a script to do this.
You're right, and I just finished to upgrade the one transposing values *_( not formulas)_*.
It's uned in two passes.
Pass 1, select the range to transpose and call the script which will extract the values of the selected cells.
Pass 2, select the left_top of the target area and call the script which will insert the transposed values.
If the left_top wasn't moved since pass 1, the original range is cleared before the insertion of transposed values.
If some one which to have a script which always transpose without moving the left_top, the two pass aren't required.
Just ask, I will post this variant.
--[SCRIPT transposeDead]
Enregistrer le script en tant que Script : transposeDead.scpt
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Merci à Scott Lindsey & Ed.Stockly du forum [email protected]
qui m'ont aidé à construire le code récupérant le bloc sélectionné.
Sélectionnez le bloc de cellules à transposer
aller au menu Scripts , choisir Numbers puis choisir transposeDead (exécute le script une première fois)
Le script récupère les informations utiles sur le bloc à transposer
Sélectionner la première cellule du bloc destination
aller au menu Scripts , choisir Numbers puis choisir transposeDead (exécute le script une deuxième fois)
Il insère les valeurs transposés.
Comme il s'agit de valeurs les modifications éventuelles du bloc source ne seront pas répercutées.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
+++++++
Save the script as a Script transposeDead.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
une_valeur you would have to create the folder Numbers and even the folder Applications by yourself.
Thanks to Scott Lindsey & Ed.Stockly from [email protected]
which helped me to build the code grabbing the selected range.
Select a group of cells.
go to the Scripts Menu, choose Numbers, then choose transposeDead (Run the script once.)
It grabs infos about the selection
select the first cell of the destination
(can't be in the source range)
go to the Scripts Menu, choose Numbers, then choose transposeDead (Run the script one more time.)
It will insert the transposed values.
As they are values, possible changes in the source block will not be reflected.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2009/01/19
2009/01/25
2009/06/03 -- enhanced for blank cells
2010/08/31 -- enhanced quite all.
property theApp : "Numbers"
property les_valeurs : {}
property old_dName : missing value
property old_sName : missing value
property old_tName : missing value
property old_rowNum1 : missing value
property old_colNum1 : missing value
--=====
on run
local rname, rowNum2, colNum2, dName, sName, tName, rname, rowNum1, colNum1
local nb_rows, nb_columns, rows_available, rows_needed, columns_available, columns_needed, une_valeur
try
if les_valeurs = {} then (*
Here we are in the first pass.
Extract infos about the source range *)
set {old_dName, old_sName, old_tName, rname, old_rowNum1, old_colNum1, rowNum2, colNum2} to my getSelParams()
Extract the values of selected cells *)
tell application "Numbers" to tell document old_dName to tell sheet old_sName to tell table old_tName
set les_valeurs to value of cells old_rowNum1 thru rowNum2 of columns old_colNum1 thru colNum2
end tell
else --============
Here we are in the second pass *)
set nb_rows to count of les_valeurs
set nb_columns to count of item 1 of les_valeurs
set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
if {old_dName, old_sName, old_tName, old_rowNum1, old_colNum1} = {dName, sName, tName, rowNum1, colNum1} then
We didn't change the left_top of the selection so clear the original range. *)
tell application "Numbers" to tell document old_dName to tell sheet old_sName to tell table old_tName
repeat with r from 1 to nb_columns
repeat with c from 1 to nb_rows
clear cell (old_rowNum1 - 1 + r) of column (old_colNum1 - 1 + c)
end repeat -- c
end repeat -- r
end tell
end if
Now we know the starting point of the destination area. *)
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
set rows_available to (get row count)
set rows_needed to rowNum1 - 1 + nb_rows
Add rows if needed *)
if rows_needed > rows_available then
repeat (rows_needed - rows_available) times
add row below row rows_available
end repeat
end if -- rows_needed
Add columns if needed *)
set columns_available to (get column count)
set columns_needed to colNum1 - 1 + nb_columns
if columns_needed > columns_available then
repeat (columns_needed - columns_available) times
add column after column columns_available
end repeat
end if -- columns_needed
Insert the transposed values *)
repeat with r from 1 to nb_rows
repeat with c from 1 to nb_columns
set une_valeur to item c of item r of les_valeurs
tell cell (rowNum1 - 1 + r) of column (colNum1 - 1 + c)
if une_valeur is 0.0 then
clear
else
set value to une_valeur as text
end if
end tell
end repeat -- c
end repeat -- r
end tell -- Numbers
Clears the property for next use *)
set les_valeurs to {}
end if
on error
Clears the property for next use *)
set les_valeurs to {}
end try
end run
--=====
set {rowNum1, colNum1, rowNum2, colNum2} to my getCellsAddresses(dname,s_name,t_name,arange)
on getCellsAddresses(d_Name, s_Name, t_Name, r_Name)
local two_Names, row_Num1, col_Num1, row_Num2, col_Num2
tell application "Numbers"
set d_Name to name of document d_Name (* useful if we passed a number *)
tell document d_Name
set s_Name to name of sheet s_Name (* useful if we passed a number *)
tell sheet s_Name
set t_Name to name of table t_Name (* useful if we passed a number *)
end tell -- sheet
end tell -- document
end tell -- Numbers
if r_Name contains ":" then
set two_Names to my decoupe(r_Name, ":")
set {row_Num1, col_Num1} to my decipher(d_Name, s_Name, t_Name, item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
else
set {row_Num2, col_Num2} to my decipher(d_Name, s_Name, t_Name, item 2 of two_Names)
end if
else
set {row_Num1, col_Num1} to my decipher(d_Name, s_Name, t_Name, r_Name)
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
end if -- r_Name contains…
return {row_Num1, col_Num1, row_Num2, col_Num2}
end getCellsAddresses
--=====
set { dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
on getSelParams()
local r_Name, t_Name, s_Name, d_Name
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if
return {d_Name, s_Name, t_Name, r_Name} & my getCellsAddresses(d_Name, s_Name, t_Name, r_Name)
end getSelParams
--=====
set {rowNumber, columnNumber} to my decipher(docName,sheetName,tableName,cellRef)
apply to named row or named column !
on decipher(d, s, t, n)
tell application "Numbers" to tell document d to tell sheet s to tell table t to ¬
return {address of row of cell n, address of column of cell n}
end decipher
--=====
set { d_Name, s_Name, t_Name, r_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 {theDoc, theSheet, theTable, theRange}
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 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
--=====
on decoupe(t, d)
local oTIDs, l
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
--=====
--[/SCRIPT]
I will enhance the old transposeLive too.
Yvan KOENIG (VALLAURIS, France) 31 août 2010 17:58:27 -
IR Report Freeze Column Header Row
In Interactive Report, Can we freeze the column header row ? This is a most wanted requirement asked by customers. More than 50 times requested in past month.
Please helpI have been playing with this problem and came up with this potential solution that has so far worked for me.
Caveats: I am new to this type of coding so check it carefully. It only works with Internet Explorer (its what we use at work). I hope to have a Firefox version someday. Some code used was found online. I gave it proper credit in my usage.
Instrcutions:
In the HTMLHeader of the Edit Page, paste the code shown below. It will lock/freeze the header of an interactive report and (optionally), any number of columns to the left of the report.
To customize it for your needs,
1. edit the line that reads: var LOCKED_COLUMNS=2; to reflect the number of columns to be locked (0 won't lock anycolumns)
2. edit the style section that reads:
<code>
div#apexir_DATA_PANEL
width: 300px; height=200px; overflow: scroll; position:relative; float:left;
</code>
to reflect the width and height for you scrolling window.
3. optionally turn of the pagination (under Pagination in the Report Attribute pagefor the region) if you want to scroll through your entire dataset without paging [possible performance implications].
I tested this with Apex 3.2 and with several themes (1, 3 and8). Hopefully it will work for you.
The code follows:
=====================================
<code>
<script>
// This code copied from: http://javascript.about.com/library/bldom08.htm
document.getElementsByClassName = function(cl)
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++)
var classes = elem.className;
if (myclass.test(classes)) retnode.push(elem[i]);
return retnode;
// End of code copied from: http://javascript.about.com/library/bldom08.htm
var LOCKED_COLUMNS=2;
function applyCSS()
var data_Table=document.getElementsByClassName('apexir_WORKSHEET_DATA');
var tr_Tags=data_Table[0].getElementsByTagName('tr');
for (var i=0;i<tr_Tags.length;i++)
var tab_Cells=tr_Tags[i].childNodes;
for (var j=0; j<LOCKED_COLUMNS; j++)
if (tab_Cells[j].nodeName != 'TD')
{ tab_Cells[j].setAttribute('id', 'Lock_Lateral_Vertical'); }
else
{ tab_Cells[j].setAttribute('id', 'Lock_Lateral'); }
window.onload=applyCSS;
</script>
<!--[if IE]>
<style id="Lock_CSS">
div#apexir_DATA_PANEL
width: 300px; height=200px; overflow: scroll; position:relative; float:left;
table.apexir_WORKSHEET_DATA th
position: relative; z-index: 14; display: table;
top: expression(document.getElementById("apexir_DATA_PANEL").scrollTop-3);
table.apexir_WORKSHEET_DATA td
border: solid 1px grey;
td#Lock_Lateral
background-color: #999999; position: relative; z-index: 15; display: table;
left: expression(document.getElementById("apexir_DATA_PANEL").scrollLeft-3);
th#Lock_Lateral_Vertical
position: relative; z-index: 21; display: inline;
top: expression(document.getElementById("apexir_DATA_PANEL").scrollTop-3);
left: expression(document.getElementById("apexir_DATA_PANEL").scrollLeft-3);
</style>
<![endif]-->
</code>
================================
ackness -
Can I paste and keep the same columns and rows?
Paste problems. I regularly download data from the Transport for London, Oystercard website. When I used Windows I could highlight and copy on their webpage (displayed in columns and rows) and when I pasted into Excel it pasted the data in the same format (columns and rows). With iPages when I try this it pastes everything into a single downwards column. Paste and Match style does not seem to alter this just the font etc. Am I able to paste in iPages in the same format as I copy.
I'm guessing you're using Safari to access the web site. The problem is with Safari, not Pages (no "i") or Numbers. Safari just doesn't "understand" tables in web pages & puts lots of spaces and/or returns instead of the needed tabs. I long since gave up & use Camino or FireFox for copying the tables to Numbers or any other program I want the data separated by tabs. There are some web sites, Discover Card is one, that appear to have tables but the data doesn't copy as such.
-
Hi all,
I'm just filling a Numbers table from a webseite per copy & paste.
Can I swap columns and rows in Numbers like in Quantrix?
AxelHere is a new transpose script.
This one inserts formulas grabbing the contents of the original block so the transposed one reflects the changes which may be done in the original block.
It's a bit long but I post it here because it introduce some handlers allowing us to acess some interesting features.
--[SCRIPT transposeLive]
Enregistrer le script en tant qu'Application ou Progiciel : transposeLive].app
déplacer l'application créée dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Merci à Scott Lindsey & Ed.Stockly du forum [email protected]
qui m'ont aidé à construire le code récupérant le bloc sélectionné.
Sélectionnez le bloc de cellules à transposer
menu Scripts > Numbers > transposeLive (exécute le script une première fois)
Le script récupère les informations utiles sur le bloc à transposer
Sélectionner la première cellule du bloc destination
(elle ne peut être dans le bloc source)
menu Scripts > Numbers > transposeLive (exécute le script une deuxième fois)
Il insère des formules récupérant le contenu du bloc transposé.
Les modifications au contenu du bloc source seront répercutées.
+++++++
Save the script as an Application or an Application Bundle: transposeLive].app
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Thanks to Scott Lindsey & Ed.Stockly from [email protected]
which helped me to build the code grabbing the selected range.
Select a group of cells.
menu Scripts > Numbers > transposeLive (Run the script once.)
It grabs infos about the selection
select the first cell of the destination
(can't be in the source range)
menu Scripts > Numbers > transposeLive (Run the script one more time.
It will insert formulas grabbing the transposed range.
Changes in the source one will be reflected.
Yvan KOENIG (Vallauris, FRANCE)
19 janvier 2009
property theApp : "Numbers"
property sourceCell : missing value
property sourceTable : missing value
property sourceSheet : missing value
property nbRows : missing value
property nbColumns : missing value
--=====
on run
set firstPass to sourceCell = missing value
if firstPass then (*
Here we are in the first pass.
We grab infos about the source range *)
set {rName, sourceTable, sourceSheet, dName} to my getSelection()
if rName is missing value then error "No selected cells"
set twoNames to my decoupe(rName, ":")
if sourceTable does not start with "'" then set sourceTable to "'" & sourceTable & "'"
if sourceSheet does not start with "'" then set sourceSheet to "'" & sourceSheet & "'"
set sourceCell to item 1 of twoNames
set {colNum1, rowNum1} to my decipher(item 1 of twoNames)
if item 2 of twoNames = item 1 of twoNames then
set {colNum2, rowNum2} to {colNum1, rowNum1}
else
set {colNum2, rowNum2} to my decipher(item 2 of twoNames)
end if
set nbRows to rowNum2 + 1 - rowNum1
set nbColumns to colNum2 + 1 - colNum1
else --**************
Here we are in the second pass
We insert formulas grabbing the transposed cells *)
set deci to character 2 of (0.5 as text)
if deci is "." then
set delim to ","
else
set delim to ";"
end if
set p2lproj to my getLproj(theApp)
set OFFSET_loc to my getLocalizedFuncName(p2lproj, "OFFSET")
--set ADDRESS_loc to my getLocalizedFuncName(p2lproj, "ADDRESS")
--set INDIRECT_loc to my getLocalizedFuncName(p2lproj, "INDIRECT")
set {rName, tName, sName, dName} to my getSelection()
if rName is missing value then error "No selected cells"
set twoNames to my decoupe(rName, ":")
set {colNum1, rowNum1} to my decipher(item 1 of twoNames)
if item 2 of twoNames = item 1 of twoNames then
set {colNum2, rowNum2} to {colNum1, rowNum1}
else
set {colNum2, rowNum2} to my decipher(item 2 of twoNames)
end if
(* Here we know the starting point of the destination area. *)
tell application theApp
activate
tell document dName to tell sheet sName to tell table tName
set rowsCible to (get row count)
set rowsNeeded to rowsCible - 1 + nbColumns
if rowsNeeded > rowsCible then
repeat (rowsNeeded - rowsCible) times
add row below row rowsCible
end repeat
end if -- rowsNeeded
set columnsCible to (get column count)
set columnsNeeded to columnsCible - 1 + nbRows
if columnsNeeded > columnsCible then
repeat (columnsNeeded - columnsCible) times
add column after column columnsCible
end repeat
end if -- columnsNeeded
repeat with i from 1 to nbRows
repeat with j from 1 to nbColumns
set value of cell (colNum1 - 1 + i) of row (rowNum1 - 1 + j) to "=" & OFFSET_loc & "(" & sourceSheet & " :: " & sourceTable & " :: " & sourceCell & delim & i - 1 & delim & j - 1 & ")"
end repeat
end repeat
end tell -- table of sheet of document
end tell -- Application
set sourceCell to missing value
set sourceTable to missing value
set sourceSheet to missing value
set nbRows to missing value
set nbColumns to missing value
end if
end run
--=====
on getSelection()
local mySelectedRanges, sheetRanges, thisRange, _, myRange, myTable, mySheet, myDoc, mySelection
tell application theApp
activate
tell document 1
set mySelectedRanges to selection range of every table of every sheet whose it is not missing value
repeat with sheetRanges in mySelectedRanges
try
count of sheetRanges
on error
set sheetRanges to {sheetRanges}
end try
repeat with thisRange in sheetRanges
if contents of thisRange is not missing value then
try
--return thisRange --poorly formed result
thisRange as text
on error errMsg number errNum
set {_, myRange, _, myTable, _, mySheet, _, myDoc} to my decoupe(errMsg, quote)
--set mySelection to (a reference to (range rn of table tn of sheet sn))
return {myRange, myTable, mySheet, myDoc}
end try
end if -- contents…
end repeat -- thisRange
end repeat -- sheetRanges
end tell -- document 1
end tell -- application
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decipher(n)
local letters, colNum, rowNum
set letters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if (character 2 of n) as text > "9" then
set colNum to (offset of (character 1 of n) in letters) * 64 + (offset of (character 2 of n) in letters)
set rowNum to (text 3 thru -1 of n) as integer
else
set colNum to offset of (character 1 of n) in letters
set rowNum to (text 2 thru -1 of n) as integer
end if
return {colNum, rowNum}
end decipher
--=====
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 getLproj(a)
local lprojs, localId, lproj
set lprojs to {{"da_DK", "da.lproj"}, {"nl_NL", "Dutch.lproj"}, {"en_US", "English.lproj"}, {"fi_FI", "fi.lproj"}, {"fr_FR", "French.lproj"}, {"de_DE", "German.lproj"}, {"it_IT", "Italian.lproj"}, {"ja_JP", "Japanese.lproj"}, {"ko_KR", "ko.lproj"}, {"no_NO", "no.lproj"}, {"pl_PL", "pl.lproj"}, {"pt_BR", "pt.lproj"}, {"pt_PT", "pt_PT.lproj"}, {"ru_RU", "ru.lproj"}, {"es_ES", "Spanish.lproj"}, {"sv_SE", "sv.lproj"}, {"zf_CN", "zh_CN.lproj"}, {"zh_TW", "zh_TW.lproj"}}
set localId to my getLocale(a, "http://support.apple.com/en_US/manuals/#iwork")
set localId to text (1 + (count of "http://support.apple.com/")) thru -1 of localId
set localId to text 1 thru ((offset of "/" in localId) - 1) of localId
set lproj to ""
repeat with i from 1 to count of lprojs
if localId is item 1 of item i of lprojs then
set lproj to item 2 of item i of lprojs
exit repeat
end if
end repeat
if lproj = "" then error "A Frameworks file is missing !"
return (path to application support as text) & "iWork '09:Frameworks:SFTabular.framework:Versions:A:Resources:" & lproj
end getLproj
--=====
on getLocale(a, x)
tell application a to return localized string x
end getLocale
--=====
on getLocalizedFuncName(f, x)
return localized string x from table "Localizable" in bundle file f
end getLocalizedFuncName
--=====
--[/SCRIPT]
Yvan KOENIG (from FRANCE lundi 19 janvier 2009 18:57:48) -
Table: ABC
Column: Changed_Date DataType:Date
Need a query which will sort the records by changed date in descending order and retrieve the latest record.
For instance.
1 13/05/2010 14:56:00
2 13/05/2010 14:56:00
3 13/05/2010 14:55:56
4 13/05/2010 14:55:54
Query should return the first row; The changed Date column is of Date datatype and not Timestamp.Sudhakar_B wrote:
Is this what you want?
select * from
(select * from some_table
order by changed_date desc)
where rownum < 2
;vr,
Sudhakar B.this is certainly a good solution, but ... if we are talking about "latest record" what if there can be two records with exactly same time?
select * from some_table where changed_date = (SELECT MAX(changed_date) from some_table) -
How to return only 1 row of data
Hi,
My problem if the table looks similar to the 1 below.
ID pay_cycle pymnt_dt
1 PAY 12/01/2006
1 EX 12/05/2006
2 PAY 12/08/2006
If the ID (such as ID 1) has a pay cycle of EX, I only want to get its payment date. I don't want it to return any other rows. However if the ID has no pay_cycle of EX (such as ID 2) I want it to return the pymnt_dt of PAY. Is this possible through SQL? I am planning to place the SQL on a table view.Hi,
I tried to join the query to other tables but I am getting an invalid column name error
SELECT
C.OPRID ,
A.SHEET_ID ,
A.SHEET_NAME ,
B.NAME ,
A.EMPLID ,
A.SHEET_STATUS ,
A.CREATION_DT ,
A.APPROVAL_DT ,
z.PYMNT_DT
FROM
PS_EX_SHEET_HDR A ,
PS_PERSONAL_DATA B ,
PSOPRDEFN C ,
PS_EX_SHEET_APRVL D ,
( SELECT DISTINCT sheet_id,
pymnt_dt FROM ( SELECT sheet_id,
pay_cycle,
pymnt_dt,
seq_nbr,
line_nbr,
row_number() OVER (PARTITION BY sheet_id ORDER BY pay_cycle DESC) rn FROM ps_ex_sheet_pymnt )
WHERE
rn = 1) z WHERE A.SHEET_STATUS='PD' AND
A.POST_STATUS_EX IN ('P','N') AND
A.APPROVAL_LEVEL IN ('S','T','B','I') AND
D.SHEET_ID = A.SHEET_ID AND
D.APPROVER_TYPE = 'T' AND
D.APPROVAL_STATUS NOT IN ('A', 'D') AND
B.EMPLID = A.EMPLID AND
A.SHEET_ID = z.SHEET_ID AND
z.SEQ_NBR = ( SELECT MAX(SEQ_NBR) FROM PS_EX_SHEET_PYMNT X , PS_EX_SHEET_LINE T WHERE E.SHEET_ID = X.SHEET_ID AND
X.SHEET_ID = T.SHEET_ID AND
X.LINE_NBR = T.LINE_NBR) AND
z.EMPLID = A.EMPLID AND
A.EMPLID NOT IN ( SELECT X.EMPLID FROM PSOPRDEFN X WHERE X.OPRID = C.OPRID) ;
Maybe you are looking for
-
I am running Lion (10.7.4) on my 2010 13" MBP. When I press my Left Shift and various Num Keys (1-9), I get Euro characters (⁄ € ‹ › fi fl ‡ ° · ‚). When I use my Right Shift, I get the standard American characters (! @ # $ % ^ & * ( )). I have already
-
Highlight filename AND extension
Within the Finder when I select a file and press ENTER or RETURN only the filename is highlighted NOT the filename extension. (I have SHOW filename extensions set to ON.) It used to work in Tiger. Is there a way to change this?
-
I just found All the Hyperlink in the Safari Print Output are gone !
Hi Everyone, My Macbook Air is Mac OS X Version 10.6.8 and Safari is 5.1 (6534.50). In previous, I could find and use the Hyperlink in the Safari Print Output (after I printed the Web Page to PDF). Hours ago, I found All the Hyperlink in the Safari P
-
Oracle Warehouse Builder 10g installation issues
Hi All, I have downloaded the OWB 10g, from the site. I have Oracle 10g (Release 2) database server installed on the machine. When I start installing Oracle Warehouse Builder 10g, it just does the client installation and I am not able to find out wer
-
Hello, I have an old Ipod and want to reset it for my little niece's new toy for Christmas. Someone has put in a password (not me) and not a clue what it is. I followed the instructions to reset it, but it is stuck. I have iTunes open, and the scre