ALV - HOW create tow rows of columns of title ?
at ALV report - how to create two ( or more ) rows ?
for example : at columns no 1 : at first row title is : NAME OF
second row title : FAMILY
at columns no 2 : at first row - title is : PLACE OF
at second row- title : COMPANY
THANKS,
AVI
all the header deatil pass through single internal table.
example
name add phone header
test q1 34 body
name add phone header
test q1 34 body
Similar Messages
-
How to convert rows to columns in sql server 2008
How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)
Lookup the Pivot transformation. From BOL:
The Pivot transformation makes a normalized data set into a less normalized
but more compact version by pivoting the input data on a column value. For
example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
null values.
When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
The column is passed through unchanged to the output. Because many input rows
can result only in one output row, the transformation copies only the first
input value for the column.
The column acts as the key or part of the key that identifies a set of
records.
The column defines the pivot. The values in this column are associated with
columns in the pivoted dataset.
The column contains values that are placed in the columns that the pivot
creates.
Paul -
How to convert rows into column
Hi,
can any one help me how to convert rows into column by pl/sql procedure.
Thanks and Regardshttp://www.oracle.com/technology/oramag/code/tips2004/050304.html
-- dropping the sample table if exists
drop table rowstocol
-- create sample table
create table rowstocol ( name varchar2(20));
-- Inserting rows into sample table
insert into rowstocol values('Amit Zhankar');
insert into rowstocol values('Piyu Yawalkar');
insert into rowstocol values('Piyu Yawalkar');
insert into rowstocol values('Ashish Ghelani');
insert into rowstocol values('Aditi Zhankar');
insert into rowstocol values('Tom Kyte');
insert into rowstocol values('Oracle');
-- Following query should be run to create a sql. This result sql should be run to convert rows to column.
-- The following query uses just the tablename (whose data is to be converted) and name of the column (which is to be converted).
-- Example taken here is table rowstocol, column name.
SELECT cc
FROM (select decode(rn ,1 ,'Select ',null) ||' MAX (CASE WHEN dr = '|| rownum||' THEN DECODE (rn,1, col1) END) '||
decode(rn,maxr,' col1 from ','||'||chr(39)||','||chr(39)||'|| ') cc,rn,maxr
from (SELECT ROWNUM rn,count(0) over() maxr FROM rowstocol) order by rn) trows
union all
select '(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn' cc from dual;
-- The result of this query will do the reqd conversion from row to column.
-- Replace table rowstocol by your table, column name by your column.
CC
Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn
Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn;
COL1
Aditi Zhankar,Amit Zhankar,Ashish Ghelani,Oracle,Oracle,Piyu Yawalkar,Piyu Yawalkar,Tom Kyte
Edited by: bhooma on Jan 20, 2009 2:44 AM -
How to convert rows into columns with decode function
Hi,
How to convert rows into columns with the help of decode function in oracle.
thanks and regards
P Prakashsay
col1 col2
1 10
2 20
3 30
then use
select col1,
sum(decode(col2,10,10)) "new1"
sum(decode(col2,20,20))"new2"
sum(decode(col2,30,30))"new3"
from table_name
group by col1;
we used sum u can use ny function if wont u have to give the column name i.e col2 name also
so i think u got it nw
regards -
How to design rows and columns in sapscript layout
Hi friends,
Please let me know how to design rows and columns in sapscript layout with example?
Thanks,
YogeshHi friends,
Please let me know how to design rows and columns in sapscript layout with example?
Thanks,
Yogesh -
How to display row to columns without using pivot keyword
hi,
could someone help me how to dispaly rows into columns without using pivot keyword and actuall my scenario is,iam having two tables with names and sample data is shown below
ID PROJECT MID MINAME TASKID TASKNAME
1 PROJ1 1 AA 100 PR1_TASK1
1 PROJ1 3 CC 102 PR1_TASK3
1 PROJ1 4 DD 103 PR1_TASK4
1 PROJ1 5 EE 104 PR1_TASK5
1 PROJ1 6 FF 105 PR1_TASK6
2 PROJ2 5 EE 114 PR2_TASK1
2 PROJ2 6 FF 115 PR2_TASK2
2 PROJ2 7 GG 116 PR2_TASK3
2 PROJ2 8 HH 117 PR2_TASK4
2 PROJ2 9 JJ 118 PR2_TASK5
2 PROJ2 10 KK 119 PR2_TASK6
2 PROJ2 1 AA 120 PR2_TASK7
The output should display project and count of tasks in particular milestone as shown below
project AA BB CC DD EE FF GG HH JJ KK
1 2 0 1 5 3 2 0 2 1 0
2 1 2 0 2 1 0 2 4 3 1
Thanks in advance ,
vvrWITH t1 AS
(SELECT 1 ID,
'PROJ1' PROJECT,
1 MID,
'AA' MINAME,
100 TASKID,
'PR1_TASK1' TASKNAME
FROM DUAL
UNION
SELECT 1, 'PROJ1', 3, 'CC', 102, 'PR1_TASK3'
FROM DUAL
UNION
SELECT 1, 'PROJ1', 4, 'DD', 103, 'PR1_TASK4'
FROM DUAL
UNION
SELECT 1, 'PROJ1', 5, 'EE', 104, 'PR1_TASK5'
FROM DUAL
UNION
SELECT 1, 'PROJ1', 6, 'FF', 105, 'PR1_TASK6'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 5, 'EE', 114, 'PR2_TASK1'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 6, 'FF', 115, 'PR2_TASK2'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 7, 'GG', 116, 'PR2_TASK3'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 8, 'HH', 117, 'PR2_TASK4'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 9, 'JJ', 118, 'PR1_TASK5'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 10, 'KK', 119, 'PR1_TASK6'
FROM DUAL
UNION
SELECT 2, 'PROJ2', 1, 'AA', 120, 'PR1_TASK7' FROM DUAL)
SELECT id project,
NVL((SELECT mid
FROM t1
WHERE miname = 'AA'
AND id = t_out.id),
0) AA,
NVL((SELECT mid
FROM t1
WHERE miname = 'BB'
AND id = t_out.id),
0) BB,
NVL((SELECT mid
FROM t1
WHERE miname = 'CC'
AND id = t_out.id),
0) CC,
NVL((SELECT mid
FROM t1
WHERE miname = 'DD'
AND id = t_out.id),
0) DD,
NVL((SELECT mid
FROM t1
WHERE miname = 'EE'
AND id = t_out.id),
0) EE,
NVL((SELECT mid
FROM t1
WHERE miname = 'FF'
AND id = t_out.id),
0) FF,
NVL((SELECT mid
FROM t1
WHERE miname = 'GG'
AND id = t_out.id),
0) GG,
NVL((SELECT mid
FROM t1
WHERE miname = 'HH'
AND id = t_out.id),
0) HH,
NVL((SELECT mid
FROM t1
WHERE miname = 'JJ'
AND id = t_out.id),
0) JJ,
NVL((SELECT mid
FROM t1
WHERE miname = 'KK'
AND id = t_out.id),
0) KK
FROM (SELECT DISTINCT id FROM t1) t_out
PROJECT AA BB CC DD EE FF GG HH JJ KK
1 1 0 3 4 5 6 0 0 0 0
2 1 0 0 0 5 6 7 8 9 10As I understand, you want MID of MINAMEs displayed ? But output is not like yours.. What is exactly your requirements? -
How to convert rows into columns
Hi,
How to convert rows into columns of two different tables.
These two tables have two common columns namely (shipline,pos).
Let me know if we have any built in functions to do this.
thank you very much .
Edited by: 808542 on Dec 7, 2010 8:35 PM
Edited by: 808542 on Dec 7, 2010 8:37 PMHave you tried this first?
http://forums.oracle.com/forums/search.jspa?threadID=&q=row+to+column&objID=f75&dateRange=last90days&userID=&numResults=15&rankBy=10001 -
How to transpose rows to columns and columns to rows in alv grid
can u plz tell me in alv grid how to
display data from itab having data
1
2
3 and so on
how to print in alv in a single row ie
1 2 3 and so onchk this code...
REPORT Z_TRANSPOSEALV .
* Type pools declaration for ALV
TYPE-POOLS: slis.
*Declarations for ALV, dynamic table and col no for transpose
DATA: l_col TYPE sy-tabix,
l_structure TYPE REF TO data,
l_dyntable TYPE REF TO data,
wa_lvc_cat TYPE lvc_s_fcat,
lt_lvc_cat TYPE lvc_t_fcat,
lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.
*Field symbols declarations
FIELD-SYMBOLS :
<header> TYPE ANY,
<dynheader> TYPE ANY,
<dyndata> TYPE ANY,
<ls_table> TYPE ANY,
<dynamictable> TYPE STANDARD TABLE,
<it_table> TYPE STANDARD TABLE.
*Input the name of the table
PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY.
*Initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
* Create internal table of dynamic type
CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
WITH NON-UNIQUE DEFAULT KEY.
ASSIGN l_dyntable->* TO <it_table>.
*select statement to select data from the table as input into
*our dynamic internal table.
*Here i have restricted only till 5 rows.
*You can set a variable and give no of rows to be fetched
*The variable can be set in your select statement
SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
FROM (p_table) up to 5 rows.
*Fieldcatalogue definitions
wa_lvc_cat-fieldname = 'COLUMNTEXT'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat.
wa_fieldcat-fieldname = 'COLUMNTEXT'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
wa_fieldcat-key = 'X'..
APPEND wa_fieldcat TO lt_fieldcat.
DESCRIBE TABLE <it_table>.
DO sy-tfill TIMES.
* For each line, a column 'VALUEx' is created in the fieldcatalog
* Build Fieldcatalog
WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
CONCATENATE 'VALUE' wa_lvc_cat-fieldname
INTO wa_lvc_cat-fieldname.
wa_lvc_cat-ref_field = 'VALUE'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat.
* Build Fieldcatalog
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
wa_fieldcat-ref_fieldname = 'VALUE'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
APPEND wa_fieldcat TO lt_fieldcat.
ENDDO.
* Create dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_lvc_cat
IMPORTING
ep_table = l_dyntable. ASSIGN l_dyntable->* TO <dynamictable>.
* Create structure as structure of the internal table
CREATE DATA l_structure LIKE LINE OF <dynamictable>.
ASSIGN l_structure->* TO <header>.
* Create structure = structure of the internal table
CREATE DATA l_structure LIKE LINE OF <it_table>.
ASSIGN l_structure->* TO <ls_table>.
* Create field catalog from our table structure
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_table
CHANGING
ct_fieldcat = lt_fieldcatalogue
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. DESCRIBE TABLE lt_fieldcatalogue.
* Fill the internal to display <dynamictable>
DO sy-tfill TIMES.
IF sy-index = 1.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
ENDIF.
* For each field of it_table
ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
* Fill 1st column
<dynheader> = wa_fieldcat-seltext_m.
IF <dynheader> IS INITIAL.
<dynheader> = wa_fieldcat-fieldname.
ENDIF.
*Filling the other columns
LOOP AT <it_table> INTO <ls_table>.
l_col = sy-tabix + 1.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
IF sy-subrc NE 0. EXIT .ENDIF.
ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
<dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
ENDLOOP.
APPEND <header> TO <dynamictable>.
ENDDO.
*Layout for ALV output
lt_layout-zebra = 'X'.
lt_layout-no_colhead = 'X'..
lt_layout-colwidth_optimize ='X'.
lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.
*ALV Grid output for display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lt_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <dynamictable>. -
How to display Rows as Columns in JSF?
I am using dataTable component to get data for my Menu, i have one column in it which returns me the data, because its automatically adding <tr> and <td> tags to it, its showing data in tabular form.
I want to show output Horizontally instead of Vertically the way its showing.
Is their any way i can display Rows as Columns?
Code:
==============================================
<div class="bodyarea">
<div id="location">
<h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
<f:verbatim><ol></f:verbatim>
<h:column>
<f:verbatim><li></f:verbatim>
<h:outputLink id="crumbID" value="#{bread.menuLink}">
<h:outputText id="crumpName" value="#{bread.menuLabel}"/>
</h:outputLink>
<f:verbatim></li></f:verbatim>
</h:column>
<f:verbatim></ol></f:verbatim>
</h:dataTable>
</div>
</div>
Thank youTable is not the html element for you, in this situation.
I would use a dataList component (distributed with myfaces implementation).
dataList is able to return a list of item, and using css you will be able display in a horizontal grid. (otherwise you can use layout="grid" in dataList).
Anyway...my impression is that who made JSF was not really understanding how a html programmer like to write his code.
Why do JSF gives us only the possibility to write list of items throught tables?
Why do JSF prints error messages throught tables?
Why div is not a standard component?
This is an incredible lack...
I see also other incredible lasks...but they don't concern html ;) . -
How to convert row into column
Hi All,
My oracle apps version is r12 and db is 10 and i am using Bi publisher version 10g.
Is it possible to convert row into column in Rtf template,
My Query is
SELECT distinct pvs.vendor_site_code,sum(aia.invoice_amount)
FROM ap_invoices_all aia, po_vendors po, po_vendor_sites_all pvs
WHERE aia.org_id = pvs.org_id
AND aia.vendor_id = po.vendor_id
AND aia.vendor_site_id = pvs.vendor_site_id
AND aia.org_id=204
group by pvs.vendor_site_code
And output is like this
Vendor sitecode Invoiceamt
EAM-ERS 79240
STAR GATE - PAY 3245902.31
UPS - HQ 10792040.9
Like this
So in template i need the output like this
Vendor sitecode EAM-ERS STAR GATE - PAY UPS - HQ
Invoiceamt 79240 3245902.31 10792040.9
I tried to achieve the output using sql query but by hardcoding only i have achieved it, so i have tried to convert directly in RTF template.
can any one tell me is it possible.
And if new project is added from the front end ie(now the query will produce 4 rows but now in template i have created only three columns)
Is it possible to add a new column dynamically.
Can any one please guide me and tell me is there any example.
Thanks & regards
SrikkanthTake a look at this post: http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=MT%3aENTRY%3a5001
Thanks,
Bipuser -
How to freeze row and column in JTable
Hi,
I need to freeze first two rows and columns in a large JTable. I found ways to freeze either a row or a column, but not both at the same time.
Can any of you help ?
Found this code which allows freezing a col. Similar method can be used to freeze column
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;
public class FrozenTablePane extends JScrollPane{
public FrozenTablePane(JTable table, int colsToFreeze){
super(table);
TableModel model = table.getModel();
//create a frozen model
TableModel frozenModel = new DefaultTableModel(
model.getRowCount(),
colsToFreeze);
//populate the frozen model
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < colsToFreeze; j++) {
String value = (String) model.getValueAt(i, j);
frozenModel.setValueAt(value, i, j);
//create frozen table
JTable frozenTable = new JTable(frozenModel);
//remove the frozen columns from the original table
for (int j = 0; j < colsToFreeze; j++) {
table.removeColumn(table.getColumnModel().getColumn(0));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//format the frozen table
JTableHeader header = table.getTableHeader();
frozenTable.setBackground(header.getBackground());
frozenTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
frozenTable.setEnabled(false);
//set frozen table as row header view
JViewport viewport = new JViewport();
viewport.setView(frozenTable);
viewport.setPreferredSize(frozenTable.getPreferredSize());
setRowHeaderView(viewport);
setCorner(JScrollPane.UPPER_LEFT_CORNER, frozenTable.getTableHeader());
}Hi,
I need to freeze first two rows and columns in a large JTable. I found ways to freeze either a row or a column, but not both at the same time.
Can any of you help ?
Found this code which allows freezing a col. Similar method can be used to freeze column
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;
public class FrozenTablePane extends JScrollPane{
public FrozenTablePane(JTable table, int colsToFreeze){
super(table);
TableModel model = table.getModel();
//create a frozen model
TableModel frozenModel = new DefaultTableModel(
model.getRowCount(),
colsToFreeze);
//populate the frozen model
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < colsToFreeze; j++) {
String value = (String) model.getValueAt(i, j);
frozenModel.setValueAt(value, i, j);
//create frozen table
JTable frozenTable = new JTable(frozenModel);
//remove the frozen columns from the original table
for (int j = 0; j < colsToFreeze; j++) {
table.removeColumn(table.getColumnModel().getColumn(0));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//format the frozen table
JTableHeader header = table.getTableHeader();
frozenTable.setBackground(header.getBackground());
frozenTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
frozenTable.setEnabled(false);
//set frozen table as row header view
JViewport viewport = new JViewport();
viewport.setView(frozenTable);
viewport.setPreferredSize(frozenTable.getPreferredSize());
setRowHeaderView(viewport);
setCorner(JScrollPane.UPPER_LEFT_CORNER, frozenTable.getTableHeader());
} -
How to color Rows and Columns of BI Query
Hi to all,
I have created BI query in query designer, with 2 structures for rows and Columns.
Now I need that certain rows can be colored orange and certain columns as green color.
I knew that it can be done in Query designer, but slice and dice reporting can not be done, which I required in my report.
Is there any way I can do in WAD.
or any other way to do that.
i shall be thankfull to you for this.
Regards
Pavneet RanaHi Rana,
You can do the coloring of KF values using the report designer tool.
Check the below links
http://help.sap.com/SAPhelp_nw70/helpdata/en/dd/cea14119eb9f09e10000000a155106/frameset.htm
[Creating Formatted reports using BEx Report Designer|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00ae5173-6112-2d10-d78f-e7779d269f25?QuickLink=index&overridelayout=true]
Regards
KP -
How to Convert Rows to Column in Query
Dear All,
I'm having problems in converting the data from rows into columns. Eg:
- item A sold on 01/01/07 = 5 kg
- item A sold on 10/01/07 = 5 kg
total item A sold in "JAN" = 10kg
- item A sold on 01/03/07 = 20 kg
total item A sold in "Mar" = 20kg
I did a query and it appear as below (in which I need the period as column)
Item Qty Period
A 10 2007-01
A 20 2007-03
The output I need is :
Item Jan Feb Mar
A 10 - 20
I've refer to the query posted in "Item History Query", even though I can get the column from Jan - Dec, but the total quantity for each month is not accurate. Please advise, and thanks for your time.
Cheers,
SereneHello Serene,
The Quantities will not be correct because you are using a Period Code in the Selection Criteria but it is not checked in the Select Statement.
But rewriting the code would cause duplicate entries for each item per months because of how the Group by clause works.
CHECK THIS
SELECT T1.ItemCode, T1.Dscription,
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 1 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JAN',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 2 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'FEB',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 3 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAR',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 4 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'APR',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 5 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'MAY',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 6 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUN',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 7 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'JUL',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 8 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'AUG',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 9 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'SEP',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 10 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'OCT',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 11 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'NOV',
(SELECT SUM(QUANTITY) FROM INV1 WHERE MONTH(DOCDATE) = 12 AND ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'DEC',
(SELECT SUM(QUANTITY) FROM INV1 WHERE ITEMCODE = T1.ItemCode AND DOCDATE >= T2.F_RefDate AND DOCDATE <= T_RefDate) AS 'TOTAL'
FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OFPR T2 ON T0.FinncPriod = T2.AbsEntry
WHERE T0.CardName ='[%A]' AND T2.Code >='[%1]' AND T2.Code <='[%2]'
GROUP BY T1.ItemCode, T1.Dscription, T2.F_RefDate, T2.T_RefDate
The Only way out of this is to declare Variable and Assign the F_RefDate and T_RefDate and then use the variables in the Select Statements.
Suda -
How to transpose rows into columns?
How do I transpose all rows into columns like how excel does?
For example:
declare @t table (ProductID int, Type varchar(20), Name varchar(20), isAvailable bit)
insert into @t
select 1, 'Type1', 'Product1',1
union
select 2, 'Type1', 'Product2',0
union
select 3, 'Type2', 'Product3',1
union
select 4, 'Type2', 'Product4',0
Results to:
ProductID Type
Name isAvailable
1 Type1
Product1 1
2 Type1
Product2 0
3 Type2
Product3 1
4 Type2
Product4 0
What I need is:
1
2
3
4
Type1
Type1
Type2
Type2
Product1
Product2
Product3
Product4
1
0
1
0
Where 1,2,3,4 at the top are the columns.select
max(case when Type='Type1' and name ='Product1' then Type end) [1],
max(case when Type='Type1' and name ='Product2' then Type end) [2],
max(case when Type='Type2' and name ='Product3' then Type end) [3],
max(case when Type='Type2' and name ='Product4' then Type end) [4]
from @t
union all
select
max(case when Type='Type1' and name ='Product1' then Name end) [1],
max(case when Type='Type1' and name ='Product2' then Name end) [2],
max(case when Type='Type2' and name ='Product3' then Name end) [3],
max(case when Type='Type2' and name ='Product4' then Name end) [4]
from @t
union all
select
max(case when Type='Type1' and name ='Product1' then cast(isAvailable as varchar(5)) end) [1],
max(case when Type='Type1' and name ='Product2' then cast(isAvailable as varchar(5)) end) [2],
max(case when Type='Type2' and name ='Product3' then cast(isAvailable as varchar(5)) end) [3],
max(case when Type='Type2' and name ='Product4' then cast(isAvailable as varchar(5)) end) [4]
from @t
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to select rows or columns of tables without using the mouse?
2nd post ever! Yeah! \m/
In Excel, I can select entire rows or columns of data WITHIN TABLES--i.e., not selecting entire sheet rows or columns--by going to any cell on the perimeter of the table, holding down shift+ctrl, and clicking a direction arrow. So for example, if I have a table in columns D-G and rows 1-5, I can highlight row 4 by going to the first or last cell of that row, holding down the shift+ctrl, and hitting the appropriate direction arrow. You might think this is superfluous given that you can use the mouse to select cells. But that becomes cumbersome with large tables, and this method can be more efficient even with small tables.
Similarly, it's often useful to navigate tables, particularly large ones, by moving from any cell within the table to the end or beginning of that row or column by holding down ctrl and hitting the appropriate arrow key. In Excel, this ctrl+arrow key method also allows you to skip blank cells, which is another very useful navigational feature.
I tried numerous combos involving shift, ctrl, command, alt/option and the arrow keys. Haven't found a way to do any of this yet.
Anyone?Hi Josh,
Numbers is organized differently than Excel, and the navigation tools are different too. Many of us miss our particular favorites from spreadsheets past, but this is Numbers, not a clone. The biggest adjustment is to go from huge monolithic sheet-tables containing virtual sub-tables to a simple blank sheet with small tables, sometimes many per sheet. Navigating is no big deal in these small tables and neither is getting from one small table to another, using the Sheets pane.
Selecting a particular Table is as easy as clicking on the table's name in the Sheets pane. Selecting a particular row, or column, or ranges of rows or columns is done by clicking on the table's row and column labels, left side and top side once a cell is selected in the table.
Numbers is weak at handling large Tables and documents that are large overall. We know this and many of us still prefer it to the alternative when the tool fits the task.
Jerry
Maybe you are looking for
-
I just upgraded to Leopard with an erase and install. After re-installing Final Cut Express and LiveType & Soundtrack, all of my Livetype files import to Final Cut with a black, blocky edge around all the letters. I tried starting a new project with
-
Hi Gurus, Appreciate if you can tell me what options i should select in flb2..... Bai or bai2....... Which option from 1 to 5 for invoice no. What algorithm .....001 and 003 or 001 and 001 or 003 and 003...... From where system will get profit centet
-
I am using oracle sqldeveloper 1.0.0.15.57. Previously we were able to set up a breakpoint and step through a stored procedure inside a package. We made sure all the previliges are on and the debugging did really work. But after some time (no changes
-
How to do I find the files I restored from my USB
Grandkids playing online video games and the whole pc crashed. Have it up and running and reinstalled programs. Cannot find the files/pictures/folders/ documents I restored that were backed up on USB
-
Safari for 10.2.8
I currently have Safari 1.0.3. Is this the latest version for my Mac? Thanks.