? Tsql query to add a sumTotal column from value in current row + value in previous row
--using Sql Server 2008 (Developer)
create table #tmp1(rowID int Identity(1,1), val1 int)
insert into #tmp1(val1)
select 5 union all
select 8 union all
select 12 union all
select 13 union all
select 22 union all
select -7 union all
select 25 union all
select 19 union all
select 32 union all
select -17
What Tsql could produce a result set as follows based on the data from #tmp1?
rowID val1 sumTotal
1 5 5
2 8 13
3 12 25
4 13 37
5 22 59
6 -7 52
7 25 77
8 19 96
9 32 128
10 -17 111
Rich P
In SQL 2008 check these links
http://social.technet.microsoft.com/wiki/contents/articles/19670.t-sql-useful-links.aspx#Running_Total
In SQL 2012 and up, the Running total can be calculated directly with ordered SUM
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Similar Messages
-
Add and remove columns from JTable
Help me please!
A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
I completely confused with it.....
Here is my code for remove column:
class DelC implements ActionListener
public void actionPerformed (ActionEvent e )
int [] HowManyColDelete = table.getSelectedColumns();
if (HowManyColDelete.length !=0)
TableColumnModel tableCModel = table.getColumnModel();
for (int i = HowManyColDelete.length-1; i>-1; i--)
table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
}It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
My brain is boiled, I've try a lot of variants of code, but did't get right result :((
It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
I understand, that my code just hide columns, not delete from table model....
But now I have not any decision of my problem...
Thanks a lot for any help. :)
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;
class JTableF extends JFrame
Object [] [] data = new Object [0] [2];
JTable table;
DefaultTableModel model;
String [] columnNames = {"1", "2"};
TableColumnModel cm;
JTableF()
super("Table features");
setDefaultLookAndFeelDecorated( true );
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar MBar = new JMenuBar();
JMenu [] menus = {new JMenu("A"), new JMenu("B")};
JMenuItem [] menu1 = {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'), new JMenuItem("Add column"), new JMenuItem("Delete column")};
menu1 [ 0 ].addActionListener(new AddL());
menu1 [ 1 ].addActionListener(new DelL());
menu1 [ 2 ].addActionListener(new AddC());
menu1 [ 3 ].addActionListener(new DelC());
for (int i=0; i<menu1.length; i++)
menus [ 0 ].add( menu1 [ i ]);
for (int i=0; i<menus.length; i++)
MBar.add(menus );
JPanel panel = new JPanel ();
model = new DefaultTableModel( data, columnNames );
table = new JTable (model);
cm = table.getColumnModel();
panel.add (new JScrollPane(table));
JButton b = new JButton ("Add row button");
b.addActionListener(new AddL());
panel.add (b);
setJMenuBar (MBar);
getContentPane().add(panel);
pack();
setLocationRelativeTo (null);
setVisible (true);
class DelC implements ActionListener
public void actionPerformed (ActionEvent e )
int [] HowManyColDelete = table.getSelectedColumns();
if (HowManyColDelete.length !=0)
TableColumnModel tableCModel = table.getColumnModel();
for (int i = HowManyColDelete.length-1; i>-1; i--)
int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
//cm = tableCModel;
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
class AddC implements ActionListener
public void actionPerformed (ActionEvent e)
//table.setColumnModel(cm);
Object NewColumnName = new String();
NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
int i = model.getRowCount();
int j = model.getColumnCount();
Object [] newData = new Object [ i ];
model.addColumn ( NewColumnName, newData);
class AddL implements ActionListener
public void actionPerformed (ActionEvent e)
int i = model.getColumnCount();
Object [] Row = new Object [ i ];
model.addRow ( Row );
class DelL implements ActionListener
public void actionPerformed (ActionEvent e)
int [] HowManyRowsDelete = table.getSelectedRows();
if (HowManyRowsDelete.length !=0)
for (int k = HowManyRowsDelete.length-1; k>-1; k--)
model.removeRow (HowManyRowsDelete[k]);
else
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
public static void main (String [] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
JTableF inst = new JTableF(); -
Hi all,
The previous query is absolutely ok.
The only thing i want to change is ...
get all the previous available ve1 AND NEW: if a AGNR has no ve1-instance, regardless get an ve1-instance with the agnr filled but f.e. the other fields empty
The grouping could made in reporting-logic later, and not in the tsql-query.
resultset i need:
- all agnr, if the have an ve1-instance or not
Groups (hierarchy) i need, later in Report:
- AGNR
- ve1 (with all the left joind fields pg, vnfk, vnpk, vm (if they are)
- if a agnr has no instance of ve1 --> print: "NO ver available"
SELECT
ve1.new_verid,
ve1.new_no,
ve1.statuscode,
ve1.statuscodename,
ve1.createdon,
ve1.createdby,
ve1.createdbyname,
ve1.new_begin,
DATEPART(yyyy, ve1.new_begin) AS begin_year,
ve1.new_end,
ve1.new_vn_fid,
ve1.new_vn_fidname,
ve1.new_vn_kid,
ve1.new_vn_kidname,
vnpk.new_how_old,
ve1.new_vg,
ve1.new_vgname,
ve1.new_vs,
ve1.new_vsname,
ve1.new_vstat,
ve1.new_vstatname,
ve1.new_zw,
ve1.new_zwname,
ve1.new_bn_zw,
ve1.new_rlz_v,
ve1.new_pgid,
ve1.new_pgidname,
pg.accountnumber as pg_accountno,
ve1.new_agnr_agnr_avmid,
ve1.new_agnr_agnr_avmidname,
AGNR.new_vm_kid AS vm_contactid,
AGNR.new_vm_kidname AS vm_contactidname,
ve1.new_efv,
ve1.new_efvname,
CASE
WHEN ve1.new_vn_kid IS NOT NULL THEN 'Private Customer'
WHEN ve1.new_vn_fid IS NOT NULL THEN 'Account Customer'
ELSE 'Kunde'
END AS kunde_typ,
DATEPART(yyyy, vnpk.birthdate) as vnpk_birth_year,
CASE
WHEN ((ve1.new_rlz_v IS NOT NULL) OR (ve1.new_rlz_v > 0))
THEN ve1.new_rlz_v
WHEN (DATEPART(yyyy, ve1.new_begin) IS NOT NULL) AND (DATEPART(yyyy, vnpk.birthdate) IS NOT NULL)
THEN 65 - ((DATEPART(yyyy, ve1.new_begin)) - (DATEPART(yyyy, vnpk.birthdate)))
ELSE 20
END AS vlz_calc,
CASE
WHEN ((ve1.new_bnj IS NOT NULL) OR (ve1.new_bnj > 0)) THEN ve1.new_bnj
WHEN ((ve1.new_bn_zw IS NOT NULL) OR (ve1.new_bn_zw > 0))
THEN
CASE
WHEN new_zw = '100000008' THEN ve1.new_bn_zw * 12
WHEN new_zw = '100000004' THEN ve1.new_bn_zw * 4
WHEN new_zw = '100000002' THEN ve1.new_bn_zw * 2
WHEN new_zw = '100000001' THEN ve1.new_bn_zw * 1
WHEN new_zw = '100000006' THEN ve1.new_bn_zw
ELSE 0
END
ELSE 0
END AS bnj_calc
FROM
Filterednew_ver AS ve1
LEFT OUTER JOIN Filterednew_agnr AS AGNR
ON ve1.new_agnr_agnr_avmid = AGNR.new_agnrid
LEFT OUTER JOIN FilteredAccount AS pg
ON ve1.new_pgid = pg.accountid
LEFT OUTER JOIN FilteredAccount AS vnfk
ON ve1.new_vn_fid = vnfk.accountid
LEFT OUTER JOIN FilteredContact AS vnpk
ON ve1.new_vn_kid = vnpk.contactid
LEFT OUTER JOIN FilteredContact AS vm
ON AGNR.new_vm_kid = vm.contactid
WHERE
(ve1.createdon >= @Begin_Week)
AND (ve1.createdon <= @End_Week)
AND (ve1.new_vg = @vg)
AND (ve1.statuscode = '1')
AND (ve1.new_efv <> '100000000' OR ve1.new_efv IS NULL)
AND (ve1.new_vstat <> '100000004' OR ve1.new_vstat IS NULL)
AND (ve1.new_zw IN ('100000008','100000004','100000002','100000001','100000006'))
ORDER BY
ve1.createdon
i thought, and tried with right joins, but i think i need to change the sight (the complete query)?
thx for all kind of help
Greets PebHi Peb,
Please provide sample data and expected results. -
Exclude column from ir in single row view
Hi Folks,
my prob: I have a very long long column (url) in my ir. In my report view I want to show it shortended and in my single row view I want to show the whole value.
So my query looks like:
select long_url, substr(long_url, 1, 30)||'...' short_url
from something;
Then I exclude the long_url column interactively with the "select columns" option in the Actions menu and save the report as standard.
Now my ir shows only the short_url in the report view, what is ok. But in the single report view it show both long_url AND short_url.
I want to get rid of the short_url in single row view. Is there any way without creating a custom form page?
Thanks!same question in other words: is there an apex variable to distinguish the report view from the detail view?
please help! -
Query on Non-base-table column in form
Hi,
Does anyone have an example of code to allow users to query on non-base-table column from forms? For example, a personnel form displays a persons' name and department name. The form is based on PERSON table, which contains the department id, not the name. The form uses post-query to display the department name. When in query mode, the user wants to enter department name, and display the people in the department (still using this form, which is based on PERSON table.
Thanks!Try this:
For data block person set these properties as follows:
1.Set Query Data Source Name = "person , departments"
2.Set DML data target name = "person"
3.Set Where Clause to join i.e. condition "person.dno = departments.dno"
For filed department name set these properties as follows:
1.Data base item = "Yes"
2.Column Name = "departments.dname"
3.Query Only = "Yes"
4.Insert Allowed = "No"
5.Update Allowed= "No"
6.Keyboard Navigable = "No"
If you face ambiguous column name check for the same filed name exist on both tables and set column name for this filed to person.filed_name
Regards
null -
Adding 2 columns from different queries
Hi,
Could someone let me know how to add 2 integer columns from 2 different queries and display it using a third field. I will need to have 2 queries.
When I try to do it it gives me Column 'xxx' references column 'xxx', which has incompatible frequency error.
Please need your help.never mind, i did it using summary columns, thanks
-
Query to add a column in between existing cols of a table?
HI All,
I have two questions.
1. Query to add a column in between existing cols of a table? (not at the end. This is view of an order of output fields in a report)
2. How do I swap the contents of two columns in a table. Suppose in a table tab there are 2 cols , col1,col2 populated with some data.
I need a query(probably) to swap the col1 and col2 values . NOT AS A RESULT SET, BUT IT NEEDS TO GET CHANGED IN THE TABLE.
Please help !> 1. Query to add a column in between existing cols of
a table? (not at the end. This is view of an order of
output fields in a report)
Not really sensible ito DBMS - it does not care how you want to view the data. The sequence and formats of columns are what you/the application need to specify in the SQL's projection clause.
Also keep in mind to achieve this, the DBMS will need to rewrite the entire table to fit this new column in-between existing columns. This is not the best of ideas.
The projection of rows is dealt with SQL statements - not with the physical storage implementation.
> 2. How do I swap the contents of two columns in a
table. Suppose in a table tab there are 2 cols ,
col1,col2 populated with some data.
I need a query(probably) to swap the col1 and col2
values . NOT AS A RESULT SET, BUT IT NEEDS TO GET
CHANGED IN THE TABLE.
This seems to work:
SQL> create table foo_tab( c1 varchar2(10), c2 varchar2(10) );
Table created.
SQL> insert into foo_tab select TO_CHAR(rownum), TO_CHAR(object_id) from user_objects where rownum < 11;
10 rows created.
SQL> commit;
Commit complete.
SQL> select * from foo_tab;
C1 C2
1 55816
2 55817
3 55818
4 55721
5 105357
6 105358
7 105359
8 105360
9 105361
10 60222
10 rows selected.
SQL> update foo_tab set c1=c2, c2=c1;
10 rows updated.
SQL> select * from foo_tab;
C1 C2
55816 1
55817 2
55818 3
55721 4
105357 5
105358 6
105359 7
105360 8
105361 9
60222 10
10 rows selected.
SQL> -
Help for a query to add columns
Hi,
I need for a query where I should add each TableC value as an additional column.
Please suggest...
I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
Considering Id of TableA.
Sample data
TableA :
ID NAME TABLENAME ETYPE
23 Name1 TABLE NAMEA Etype A
TableB :
ID A_ID RTYPE RNAME
26 23 RTYPEA RNAMEA
61 23 RTYPEB RNAMEB
TableC :
ID B_ID COMPNAME CONC
83 26 Comp Name AA 1.5
46 26 Comp Name BB 2.2
101 61 Comp Name CC 4.2
Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
Output required: Put each TABLEC value as an additional column
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME TableC_1_CONC TableC_2_COMPNAME TableC_2_CONC
Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2 so on..
Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL
Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
Output:
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
TableC_1_CONCvalue value value value valueHi,
Welcome to the forum!
Do you want the data from TableC presented
(1) in one column, or
(2) in several columns (a different column of results for each row in the original TableC)?
(1) Is called String Aggregation and is easier than (2).
The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
Ignoring TableA for now, you could get what you want by saying
SELECT b.rtype
, STRAGG ( c.compname
|| ' '
|| c.conc
) AS c_data
FROM TableB b
JOIN TableC c ON b.id = c.b_id
GROUP BY b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
(a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
(b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
The two scripts below contain basic information on pivots.
This first script is similar to what you would do for case (a):
-- How to Pivot a Result Set (Display Rows as Columns)
-- For Oracle 10, and earlier
-- Actually, this works in any version of Oracle, but the
-- "SELECT ... PIVOT" feature introduced in Oracle 11
-- is better. (See Query 2, below.)
-- This example uses the scott.emp table.
-- Given a query that produces three rows for every department,
-- how can we show the same data in a query that has one row
-- per department, and three separate columns?
-- For example, the query below counts the number of employess
-- in each departent that have one of three given jobs:
PROMPT ========== 0. Simple COUNT ... GROUP BY ==========
SELECT deptno
, job
, COUNT (*) AS cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
, job;
Output:
DEPTNO JOB CNT
20 CLERK 2
20 MANAGER 1
30 CLERK 1
30 MANAGER 1
10 CLERK 1
10 MANAGER 1
20 ANALYST 2
PROMPT ========== 1. Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno;
-- Output:
DEPTNO ANALYST_CNT CLERK_CNT MANAGER_CNT
30 0 1 1
20 2 2 1
10 0 1 1
-- Explanation
(1) Decide what you want the output to look like.
(E.g. "I want a row for each department,
and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
(2) Get a result set where every row identifies which row
and which column of the output will be affected.
In the example above, deptno identifies the row, and
job identifies the column.
Both deptno and job happened to be in the original table.
That is not always the case; sometimes you have to
compute new columns based on the original data.
(3) Use aggregate functions and CASE (or DECODE) to produce
the pivoted columns.
The CASE statement will pick
only the rows of raw data that belong in the column.
If each cell in the output corresponds to (at most)
one row of input, then you can use MIN or MAX as the
aggregate function.
If many rows of input can be reflected in a single cell
of output, then use SUM, COUNT, AVG, STRAGG, or some other
aggregate function.
GROUP BY the column that identifies rows.
PROMPT ========== 2. Oracle 11 PIVOT ==========
WITH e AS
( -- Begin sub-query e to SELECT columns for PIVOT
SELECT deptno
, job
FROM scott.emp
) -- End sub-query e to SELECT columns for PIVOT
SELECT *
FROM e
PIVOT ( COUNT (*)
FOR job IN ( 'ANALYST' AS analyst
, 'CLERK' AS clerk
, 'MANAGER' AS manager
NOTES ON ORACLE 11 PIVOT:
(1) You must use a sub-query to select the raw columns.
An in-line view (not shown) is an example of a sub-query.
(2) GROUP BY is implied for all columns not in the PIVOT clause.
(3) Column aliases are optional.
If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
{code}
The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
{code}
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus.
(This can be easily adapted to PL/SQL or other tools.)
PROMPT ========== 0. Basic Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
ORDER BY deptno
PROMPT ========== 1. Dynamic Pivot ==========
-- ***** Start of dynamic_pivot.sql *****
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT DISTINCT
', COUNT (CASE WHEN job = '''
|| job
|| ''' ' AS txt1
, 'THEN 1 END) AS '
|| job
|| '_CNT' AS txt2
FROM scott.emp
ORDER BY txt1;
SPOOL OFF
-- Restore SQL*Plus features suppressed earlier
SET FEEDBACK ON
SET PAGESIZE 50
SPOOL p:\sql\cookbook\dynamic_pivot.lst
SELECT deptno
@@dynamic_pivot_subscript
FROM scott.emp
GROUP BY deptno
ORDER BY deptno
SPOOL OFF
-- ***** End of dynamic_pivot.sql *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one. If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one. That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
{code} -
Query Help - Add a column that doesn't exist in table
Hello,
i have an application that runs a query in code off of a main query, and that query in code requires a column that does not exist in the main query that I created. how do I go about adding a column to a query that does not actually exist in the table or database that I am querying?
For Example:
SELECT PROJ_ID, PROJECT_NAME
FROM PROJECT
I need a column called "DELETE_SESSION_ID" and this database/table does not contain that column anywhere. Is it best to create a view that creates the column somehow? I would prefer not having to create the column inside of the table. Any ideas are greatly appreciated.
Thanks,
Jeffuser10249614 wrote:
Hello,
i have an application that runs a query in code off of a main query, and that query in code requires a column that does not exist in the main query that I created. how do I go about adding a column to a query that does not actually exist in the table or database that I am querying?
For Example:
SELECT PROJ_ID, PROJECT_NAME
FROM PROJECT
I need a column called "DELETE_SESSION_ID" and this database/table does not contain that column anywhere. Is it best to create a view that creates the column somehow? I would prefer not having to create the column inside of the table. Any ideas are greatly appreciated.
Thanks,
JeffYou need a way to obtain the value you need - a function to generate it, perhaps. A view using such a function or aquiring the value by other means should work well.
Pipelined functions work well to generate values that aren't in the database at run time - if your version of Oracle supports them -
Selecting all columns from table in a model query
I have written a model query which joins 4 tables, applies some rules and returns updated rows by selecting 4 columns out of this. Currently it works fine because all 4 columns are from MODEL aliases. Now I need to select 16 more columns in the same query but none of these columns is added in MODEL aliases. When I tried selecting these columns I got oracle error ORA - 32614. Can someone please guide me to include these columns in the same model query?
I tried couple of options but no luck. Here are those options for ready reference:
1. I cannot nest existing model query into another select because there are no columns avaiable to join in output of current query to map with other records.
2. I cannot include all 16 columns in MODEL aliases because some of these columns are actually output of user defined functions.
I am using Oracle database version 11g Release 11.2.0.1.0.
Edited by: Anirudha Dhopate on Jan 23, 2011 5:43 PMThank you Avijit for your reply. There is a syntax error on the ON in this part of the statement which I don't know how to fix - I tried messing around with another INNER JOIN but am not confident that I'm doing the right thing:
SENAlertType.SENAlertTypeIDONClassMember.ClassMemberStudentID
Thanks for your help! I will need to do some more bedtime reading on joins.
Daniel -
I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year
Hi Arun ,
Can you explain little bit more ??
what is account doc no?
what are the transactions should be displayed in your output??
-Rajesh N -
Multiple columns from a query sorted vertically
Is it possible to sort a query resultset vertically, with
multiple columns across the page, in the following manner, with
page breaks after 40 rows? I can get it to sort horizontally just
fine with tables, but how can it be done vertically as shown?
JONES, Abby JONES, Betty JONES, Dawn JONES, Frank
JONES, Adam JONES, Bill JONES, Debbie JONES, Gayle
JONES, Alice JONES, Bob JONES, Denton JONES, Henry
JONES, Ben JONES, Cathy JONES, Emma JONES, JohnThis will get you started. I assume you had the appropriate
order by clause in your query. I also assume you want 4 columns per
line.
My approach would be to convert the query to an array and
then output the array.
columns = 4;
maxrows = 40;
recordsperpage = columns * rows;
records = query.recordcount;
myArray = ArrayNew(2);
ThisColumn = 1;
ThisRow = 1;
if (records gt recordsperpage)
LoopTill = recordsperpage;
else
LoopTill = records;
for ( ii = 1; ii lte LoopTill; ii = ii + 1){
myArray[ThisRow][ThisColumn] = query.field[ii];
increment ThisRow;
if (ThisRow = MaxRows + 1) {
ThisRow = 1;
increment ThisColumn;
} // if
} // looop
You can do the rest -
To fetch Query Column from a query .
Is there a way to extract the column from a database to an application written in C / Proc* C
Maybe this? You may get Name/Value pairs e.g. via
michaels> select dbms_xmlgen.getxml ('select ename,job from emp where ename=upper(''scott'')') x from dual
X
<?xml version="1.0"?>
<ROWSET>
<ROW>
<ENAME>SCOTT</ENAME>
<JOB>ANALYST</JOB>
</ROW>
</ROWSET> -
How to accessing current row report column value in Lov Query?
Hi,
which access methods (eg. bind variables, substitutions, ...) for getting the current row report column value can be used in the "Lov Query" property of a report column?
As what I know of and what I have read on the forum there are no bind variables for the report columns. For the "Link Text" property it seems that the column values exist as substitution strings (#COLUMN_NAME#). But they don't work in the Lov Query. => And would be good because of a hard parse each time the Lov query is executed.
The following post (Re: Simulating a correlated sub query in lov
is showing a solution to use package variables for temporary storage of the referenced value, but the only problem with that solution is that if a new record is added with the "Add rows to tabular form" process the package variable still contains the value from the last queried row! Is there a way (variable, APEX package, ...) to determine if the lov query is executed for a new record so that the package can return null?
I know that I could write the package in a way that the value is immediately cleared when lov_pkg.keyval is called (one time read), but then I would have to create several variables if I'm accessing the value multiple times in the query or in another query => I think an one time read solution would be very obscurely.
Thanks for your help
Patrick
http://inside-apex.blogspot.comHi Patrick,
I agree that it's a waste to continually use Ajax to go back to the server to get the contents of a dynamic select list.
There are no bind variables for any row item - but what you do have, as per my previous post, is the value of the data entered by the user in the first row. You can pass this into your application process (using get.add("VARIABLENAME", value)), which can use it to retrieve the correct LOV in your Ajax code - this will give you a "bind variable" that your process can use.
What you could do, however, is generate hidden select lists on your page - one for each possible LOV list and replace the contents of the new row's select list with the contents of the appropriate hidden select list. This is easy to do with javascript (using innerHTML functions). Obviously, though, the usefulness of this depends on the number and size of the select lists.
Even if you don't generate them to start with, you can keep a copy of any select lists returned by Ajax in the DOM for use on new rows. So, if you have retrieved a select list, you will have a copy of it in DOM which you can then copy into the new row. If you don't have the list in DOM, use Ajax to get it, store a copy of it and copy it into the new row.
Which method you use will depend on the number/size of select lists needed. If they are few in number and/or size, I would suggest generating hidden lists. If they are large, use Ajax to get them once, store them and then retrieve them from the DOM when needed.
There is another thread here where Arie recommends going to the server every time to make sure you get the most up-to-date data for the lists. If you want to follow this advice, for this reason, use get.add("VARIABLENAME", value) to pass the value to your process. If this is not an issue, you can use one of the other methods I outlined above.
Regards
Andy -
Multiple columns from the same dimension table as row labels performing slowly
(Working with SSAS tabular)
I'm trying to figure out what the approach should be for the following scenario:
Lets say we have a Customer table. The table has columns such as account number, department number, name, salesperson, account manager, number of customers, delivery route, etc
A user of the model could want to see any permutation of that information as the row labels. How should that be handled?
What we've been doing so far is that the user adds each column they want into the "ROWS" section in Excel. This works fine with smaller tables (for example, "Department" table with a "Department Code" and "Department Name",
but on large tables this quickly chokes. I understand why this is happening, I just haven't found a better way to accomplish the same thing.
I can add a calculated column to the model through VS, but obviously this is unsupportable and unscalable when each person needs their own permutations of the data. Can something similar be done in Excel?
This question seems to be what I need:
http://social.msdn.microsoft.com/Forums/en-US/97d1157a-1402-4227-b96a-79524401ddcd/mdx-query-performance-when-selecting-multiple-attributes-from-same-dimension?forum=sqlanalysisservices
However I can't find any information on how to add those properties (is it a multidimensional-only thing?)Thanks for the help. Sorry but i'm a self-taught developer, and i may be missing some basics :)
Anyway i've done what you suggested but i get this error:
[nQSError: 15011]The dimension table source Dimension Services.DM_D_SERVIZI_SRV has an aggregate content specification that specifies the level Product. But the source mapping contains column COD_PRODUCT with a functional dependency association on a more detailed level .
where:
- DM_D_SERVIZI_SRV is the physical alias for the Service Dimension (and the name of the LTS too)
- COD_PRODUCT is the leaf of the hierarchy, the physical primary key, but it hasnt to be included in the hierarchy
Do i have to add another level with the primary key and hide it to the users?
I tried to solve this going to the logical tables source properties, on the tab contents, setting "logical level" to null for the hierarchy, but i don't know if this is correct.
Thanks
Maybe you are looking for
-
Wirelss drops out - can no longer see any networks
Hi all, I have searched for other threads with similar problems but I could not find one exactly like mine. Recently I have had problems where I have been surfing on firefox, and then all of a sudden it has automatically switched to "Work Offline". I
-
How to switch multiple relays using PCI 6601 DAQ card
What is the specification of the digital output value given from the PCI 6601 DAQ card?How to develop LAB VIEW code to switch a relay?Can anybody please explain?
-
Speech analysis not working, even for english - CC 7.0.1, OSX
My research around the forum suggests that there IS a bug for this, but only for languages OTHER than english. I beg to differ... In my case, I have not installed any additional language packs, and the "Analyze..." button in the speech analysis part
-
AirTunes Remote Speaker Problem
Since updating iTunes to version 7.1 [and then 7.1.1] I've been unable to connect to my Airport Express remote speaker via iTunes. The speaker show up on the list but states that: "The Remote speaker ___ is not compatible with this version of iTunes.
-
Hi, Am getting the following error when trying to load data with any user other than an admin user Warning: Cannot load in Replace mode without full access to all accounts in the subcube. There is no additional security setup on the accounts dimensio