How to transpose rows to multiple dynamic number of columns
Hi All,
I have a requirement to transpose the rows in single column to multiple columns. The columns are not fixed.
A table called XX_PRODUCT_SIZE.
The data in the table are,
PRODUCT_NO SIZE PRESSURE
P1 1 100
P1 1 200
P1 2 100
P1 2 300
P1 3 300
The data in the table are not fixed with respect to size and pressure. In future the product P1 may have size 4 with new pressure 900.
Now I want to convert these rows into multiple columns.
So it should be,
PRODUCT_NO SIZE_1 SIZE_2 SIZE_3 PRESSURE_100 PRESSURE_200 PRESSURE_300
P1 TRUE TRUE TRUE
P1 TRUE TRUE TRUE
P1 TRUE TRUE
I tried many ways of writing using CASE, MAX with rownumber over partition by etc. but which will not work for me as the rows are not fixed to compare.
Can you please help me writing a query which transpose rows to columns dynamically. My intention is to create a materialized view for this XX_PRODUCT_SIZE table with transposing columns.
I am using 10g DB
Thank You
Manju
Edited by: ManjuNaik88 on May 28, 2013 2:29 AM
Hi,
If the number of columns in a query has to be figured out at run-time, then you need dynamic SQL. See the froum FAQ {message:id=9360005} for links to examples.
You might find it easier to create one big column that looks like a variable number of columns. SELECT ... PIVOT can do this with XML output. String aggregation is another way; see {message:id=3527823} .
ManjuNaik88 wrote:
... I saw Oracle 11g Pivot can be used. "PIVOT" is still not working
SELECT ... PIVOT works. If it's not doing what you the way you're uisng it, then just change how you're using it.
(You don't expect a mor precise answer with just that information, do you?)
Similar Messages
-
How to transpose rows into multiple columns using pivot table
I have 1 row containing 12 columns with value "JAN", "FEB", "MAR", "J-1","F-1","M-1","J-2","F-2","M-2","J-3","F-3","M-3"
I want to display as
JAN J-1 F-1 M-1
FEB J-2 F-2 M-2
MAR J-3 F-3 M-3
How do I achieve the above?Today you have only 3 months JAN, FEB, MAR. Is it always the same number of columns. What if there are more months added to this row?
Is your data really coming from relational source or some sort of text file?
There is a better way to do this in narrative view using HTML if your requirement is just to show them in multiple rows and do some calculations.
Go to Narrative View;
In prefix, use <html> <table>
In 'Narrative' text box add something like this
<tr> <td> @1 </td> <td> @4 </td> <td> @7 </td> </tr>
<tr> <td> @2 </td> <td> @5 </td> <td> @8 </td> </tr>
<tr> <td> @3 </td> <td> @6 </td> <td> @9 </td> </tr>
In Suffix, use </table> </html>
You can also add simple calculations like sum etc at the very bottom of these rows as grand totals.
kris -
Transpose row with multiple data into 3 columns / Excel Macros
Hi everyone, can you please help me with my manual intervention of transposing column data to row format?
Sample
Dates
01/01/2014
01/02/2014
01/03/2014
01/04/2014
01/05/2014
01/06/2014
01/07/2014
01/08/2014
01/09/2014
01/10/2014
01/11/2014
Name1
Value 1
Value 2
Value 3
Value 4
Value 5
Value 6
Value 7
Value 8
Value 9
Value 10
Value 11
Name2
Item1
Item2
Item3
Item4
Item6
Item7
Item8
Item9
Item10
Name3
Code1
Code2
Code4
Code5
Code6
Code7
Code8
Code9
Code10
Code11
Expected output
NAME
Date
DATA
Name1
01/01/2014
Value 1
Name1
01/02/2014
Value 2
Name1
01/03/2014
Value 3
Name1
01/04/2014
Value 4
Name1
01/05/2014
Value 5
Name1
01/06/2014
Value 6
Name1
01/07/2014
Value 7
Name1
01/08/2014
Value 8
Name1
01/09/2014
Value 9
Name1
01/10/2014
Value 10
Name1
01/11/2014
Value 11
Name2
01/01/2014
Item1
Name2
01/02/2014
Item2
Name2
01/03/2014
Item3
Name2
01/04/2014
Item4
Name2
01/05/2014
Item5
Name2
01/06/2014
Item6
Name2
01/07/2014
Item7
Name2
01/08/2014
Item8
Name2
01/10/2014
Item9
Name2
01/11/2014
Item10
Name2
01/12/2014
Item11
Name3
01/01/2014
Code1
Name3
01/02/2014
Code2
Name3
01/03/2014
Code3
Name3
01/04/2014
Code4
Name3
01/05/2014
Code5
Name3
01/06/2014
Code6
Name3
01/07/2014
Code7
Name3
01/08/2014
Code8
Name3
01/09/2014
Code9
Name3
01/10/2014
Code10
Name3
01/11/2014
Code11See my reply in
http://www.eileenslounge.com/viewtopic.php?f=27&t=17245
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
BI Layout/Template | Table with dynamic number of columns
hi!
i have a problem concerning the creation of a dynamic report with the BI publisher.
in my BI template i need a table with a dynamic number of columns. i have searched the
forums but havent really found a solution for this type of problem.
first of all this is A dummy-structure of my dataset:
<ROWSET>
<ROW>
<FIELD1>1</FIELD2>
<FIELD2>2</FIELD2>
<FIELD3>3</FIELD3>
<FIELD4>4</FIELD4>
</ROW>
<ROW>
<FIELD1>a</FIELD2>
<FIELD2>b</FIELD2>
<FIELD3>c</FIELD3>
<FIELD4>d</FIELD4>
</ROW>
</ROWSET>
in the report the fields represent the columns i need in the table.
the problem is, that the number of the fields vary. in this example i have 4 fields/columns
but another time i may have 6 or 10 etc..
my dataset is always different because i am loading my dataset via a http request which is
returning the needed data in XML.
is there a nativ possibility within the publisher to generate the columns dynamically?
i read about <?split-column-header:group element name?> etc. but this is only for cross-tables.
can anybody give me a hint how to approach this problem?
would be very glad for some advice.
thanks a lot in advance!Specific answer is here
http://winrichman.blogspot.com/2008/09/dynamic-column.html
but these link let you know, how to do
http://winrichman.blogspot.com/search/label/Dynamic%20column
http://winrichman.blogspot.com/search/label/Cross-tab
http://winrichman.blogspot.com/search/label/cross%20tab -
How to create a table with varied number of columns?
I am trying to create a balance table. The colunms should include years between the start year and end year the user will input at run time. The rows will be the customers with outstanding balance in those years.
If the user input years 2000 and 2002, the table should have columns 2000, 2001, 2002. But if the user input 2000 and 2001, the table will only have columns 2000 and 2001.
Can I do it? How? Thanka a lot.Why did you create a new thread for this?
How to create a table with varied number of columns? -
Dynamic Number of Column in a table
Hi guys,
I have a requirement that needs dynamic number of column in a tale.
It is possible to do this in Adobe forms.
Thanks,
ChirantanHello. It of course is possible in Adobe.
You need to write a simple script using JavaScript or FormCalc to hide or show columns according to some special value. You will work with the presence attribute of the object. E.g. MYFIELD.presence = "visible" or "hidden" or "invisible". You will need to change your subforms content to flowed.
Use these guides:
http://www.adobe.com/devnet/livecycle/articles/lc_designer_scripting_basics/lc_designer_scripting_basics.pdf
help.adobe.com/en_US/livecycle/es/FormCalc.pdf
Hope this helps, good luck, Otto -
How to pipeline a function with a dynamic number of columns?
Hi everyone,
I'm trying to figure out how to write a piplined function that generates a dynamic SQL statement from its inputs, executes the query, and returns the results of the query in the pipeline. The number and names of the columns in the dynamic query is unknown number until the function is invoked.
I suspect that DBMS_SQL is involved, but can't quite figure out how to construct a row using it that I can use PIPE ROW on. I also can't figure out what data type the function should return (ANYDATASET?)
pseudo-PLSQL follows:
create function myfunction ( param1 varchar2)
return anydataset pipelined
as
query_string := <... do stuff with param1 ...>
< -- >
open a cursor for query_string
determine the number of columns
read a row
PIPE ROW it
<--->
Can what I'm trying to do be done?
Thanks,
KeithThe following works on 10R2
create or replace type NColPipe as object
l_parm varchar2(10), -- The parameter given to the table function
rows_requested number, -- The parameter given to the table function
ret_type anytype, -- The return type of the table function
rows_returned number, -- The number of rows currently returned by the table function
static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
return number,
static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
return number,
static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
return number,
member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
return number,
member function ODCITableClose( self in NColPipe )
return number,
static function show( p_parm in varchar2, p_rows_req in number := 2 )
return anydataset pipelined using NColPipe
create or replace type body NColPipe as
static function ODCITableDescribe( rtype out anytype, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
atyp anytype;
begin
anytype.begincreate( dbms_types.typecode_object, atyp );
if p_parm = 'one'
then
atyp.addattr( 'one'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
elsif p_parm = 'two'
then
atyp.addattr( 'one'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( 'two'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
else
atyp.addattr( p_parm || '1'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( p_parm || '2'
, dbms_types.typecode_varchar2
, null
, null
, 10
, null
, null
atyp.addattr( p_parm || '3'
, dbms_types.typecode_number
, 10
, 0
, null
, null
, null
end if;
atyp.endcreate;
anytype.begincreate( dbms_types.typecode_table, rtype );
rtype.SetInfo( null, null, null, null, null, atyp, dbms_types.typecode_object, 0 );
rtype.endcreate();
return odciconst.success;
exception
when others then
return odciconst.error;
end;
static function ODCITablePrepare( sctx out NColPipe, ti in sys.ODCITabFuncInfo, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
elem_typ sys.anytype;
prec pls_integer;
scale pls_integer;
len pls_integer;
csid pls_integer;
csfrm pls_integer;
tc pls_integer;
aname varchar2(30);
begin
tc := ti.RetType.GetAttrElemInfo( 1, prec, scale, len, csid, csfrm, elem_typ, aname );
sctx := NColPipe( p_parm, p_rows_req, elem_typ, 0 );
return odciconst.success;
end;
static function ODCITableStart( sctx in out NColPipe, p_parm in varchar2, p_rows_req in number := 2 )
return number
is
begin
return odciconst.success;
end;
member function ODCITableFetch( self in out NColPipe, nrows in number, outset out anydataset )
return number
is
begin
anydataset.begincreate( dbms_types.typecode_object, self.ret_type, outset );
for i in self.rows_returned + 1 .. self.rows_requested
loop
outset.addinstance;
outset.piecewise();
if self.l_parm = 'one'
then
outset.setvarchar2( to_char( i ) );
elsif self.l_parm = 'two'
then
outset.setvarchar2( to_char( i ) );
outset.setvarchar2( 'row: ' || to_char( i ) );
else
outset.setvarchar2( 'row: ' || to_char( i ) );
outset.setvarchar2( 'row: ' || to_char( i ) );
outset.setnumber( i );
end if;
self.rows_returned := self.rows_returned + 1;
end loop;
outset.endcreate;
return odciconst.success;
end;
member function ODCITableClose( self in NColPipe )
return number
is
begin
return odciconst.success;
end;
end;
/And to use it
SQL> select * from table( NColPipe.show( 'test', 3 ) );
test1 test2 test3
row: 1 row: 1 1
row: 2 row: 2 2
row: 3 row: 3 3
SQL> select * from table( NColPipe.show( 'two', 5 ) );
one two
1 row: 1
2 row: 2
3 row: 3
4 row: 4
5 row: 5
SQL> select * from table( NColPipe.show( 'one' ) );
one
1
2
SQL> Anton -
Displaying tables with dynamic number of columns
Hello,
I'm pretty new to JSF. Currently I'm working on a project where I have to select a table from a list, and then make it browsable/editable. The problem I have is that the different tables also have a different number of columns.
I have no problem displaying different tables if the number of coulumns stays the same (using h:datatable) but when it's dynamic, I don't know how I can have my JSP to adjust to support the varying number of columns.
Has anyone got an example of dynamic datatable or maybe someone can point me in the right direction.
BrimborianHi daniel,
1. There is an INDEPENDENT FORM
whose inputs are FIELD LIST
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying some inputs (ie. field list)
4.
REPORT abc.
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.
START-OF-SELECTION.
GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
INDEPENDENT FORM
FORM mydyntable USING lt TYPE lvc_t_fcat .
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m. -
Generate itab with dynamic number of columns
I have a method that exports a internal table to excel, XML or HTML, which works fine in many cases.
Now I want to export some special data that I want to put into an itab first.
The problem is that both the number of columns and the number of rows are dynamic.
LOOP AT (header_table)
(for each entry, I need one column)
ENDLOOP.
LOOP AT (row_table).
(do some calculations and add a row to the itab)
ENDLOOP.
Is there a way to generate an internal table like this?Hi daniel,
1. There is an INDEPENDENT FORM
whose inputs are FIELD LIST
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying some inputs (ie. field list)
4.
REPORT abc.
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.
START-OF-SELECTION.
GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
INDEPENDENT FORM
FORM mydyntable USING lt TYPE lvc_t_fcat .
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m. -
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>. -
Hi All,
Question: How do I filter rows out of a query where multiple columns are equal to a single question mark character?
Background: I'm using SQL 2008 R2. Furthermore, the part of my brain that helps me create less-than-simple queries hasn't been working for the last 4 days, apparently, and now I need help.
We have about 4,000 rows in a table. This data set was generated from an exported report, and many of the rows in the detail table were not actual data rows but were simply "header" rows. For those table rows, most of the columns have
a single question mark as the value.
Some of the detail rows have one or more question mark values, too, so it's important that these rows don't get filtered out.
When I include criteria like "WHERE col1 <> '?' AND col2 <> '?' AND col3 <> '?' AND col4 <> '?'", all rows with a question mark value for even a single one of those columns get filtered out. How do I filter out rows
where all columns 1-4 contain a question mark value?
Thanks for your help,
EricI just tried to create to create a scenario for you. Please see ig you're looking for something like this.
Create table test_Question_mark
RecordID INT identity(1,1),
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10),
Col4 varchar(10),
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','??','??','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('?','?','?','?')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ??','??','??')
insert into test_Question_mark (Col1, Col2, Col3, col4) values ('??','test ?','??','??')
--drop table test_Questio_mark
select * from test_Question_mark
select * from test_Question_mark
WHERE
(CHARINDEX('?', Col1,1) > 0 AND CHARINDEX('?', Col1, CHARINDEX('?', Col1,1)+1) = 0) AND
(CHARINDEX('?', Col2) > 0 AND CHARINDEX('?', Col2, CHARINDEX('?', Col2,1)+1) = 0) AND
(CHARINDEX('?', Col3,1) > 0 AND CHARINDEX('?', Col3, CHARINDEX('?', Col3,1)+1) = 0) AND
(CHARINDEX('?', Col4,1) > 0 AND CHARINDEX('?', Col4, CHARINDEX('?', Col4,1)+1) = 0)
--drop table test_Questio_mark
I hope above solution will help.
Thanks!
Ashish. -
How to ADD rows to a dynamic internal table??
My question is simple.
I have a dynamic internal table and I need to ADD rows to if.
I read this thread How to modify a dynamic internal table from dynamic work area but they are modifying existing data.
My internal table is EMPTY and I need to ADD new rows, so I can't use LOOP ASSIGNING.
How can I do that?
Any help is welcome!
Thanks!
BettinaHi,
try something similar.
FIELD-SYMBOLS: <fs> type any.
FIELD-SYMBOLS: <f1> type any.
ASSIGN INITIAL LINE TO lo_data ASSIGNING <fs>. " or <f_tab> - not sure w/o editor :-)
assigning component 1 of structure <fs> to <f1>.
<f1> = 'aaa'.
I write it from memory so there can be some syntax errors but focus to command APPEND INITIAL LINE ...
Regards,
Karol -
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 get row index in dynamically populated table?
Hi,
I am following example given in http://balusc.xs4all.nl/srv/dev-jep-dat.html to Dynamically populate datatable. How can I get row index while populating table in populateDynamicDataTable() method
private List myList;
private String[] headers; // Optional.
private HtmlDataTable dynamicDataTable;
// Actions ----------------------------------------------------------
public void loadMyList() {
// Set headers (optional).
headers = new String[] {"header1", "header2", "header3"};
// Set rows. This is a stub example, just do your dynamic thing.
String[] row1 = {"ID1", "Name1", "Value1"};
String[] row2 = {"ID2", "Name2", "Value2"};
String[] row3 = {"ID3", "Name3", "Value3"};
// Convert rows to List and set the List.
myList = new ArrayList();
myList.add(Arrays.asList(row1));
myList.add(Arrays.asList(row2));
myList.add(Arrays.asList(row3));
public void populateDynamicDataTable() {
//*********************** I want current row in this method *************//
// Any columns?
if (myList != null && myList.size() > 0) {
dynamicDataTable = new HtmlDataTable();
// Get amount of columns.
int columns = ((List) myList.get(0)).size();
// Set columns.
for (int i = 0; i < columns; i++) {
// Set header (optional).
UIOutput header = new UIOutput();
header.setValue(headers);
// Set output.
UIOutput output = new UIOutput();
ValueBinding myItem =
FacesContext
.getCurrentInstance()
.getApplication()
.createValueBinding("#{myItem[" + i + "]}");
output.setValueBinding("value", myItem);
// Set column.
UIColumn column = new UIColumn();
column.setHeader(header);
column.getChildren().add(output);
// Add column.
dynamicDataTable.getChildren().add(column);
// Getters ----------------------------------------------------------
public List getMyList() {
return myList;
public HtmlDataTable getDynamicDataTable() {
if (dynamicDataTable == null) {
loadMyList(); // Reload to get most recent data.
populateDynamicDataTable();
return dynamicDataTable;
// Setters ----------------------------------------------------------
public void setMyList(List myList) {
this.myList = myList;
public void setDynamicDataTable(HtmlDataTable dynamicDataTable) {
this.dynamicDataTable = dynamicDataTable;
I have tried dynamicDataTable.getRowIndex, but it returns -1
Is there any other way?
Thanks ,
Chitra.When you dynamically populate a datatable, you're populating the columns, not the actual rows.
Just add EL to the styleClass attribute, like:styleClass="#{myBean.myTable.rowIndex == 1 ? 'highlightedClass' : 'defaultClass'}"where 'myTable' refers to a HtmlDataTable property in the backing bean. -
How to add row in multiple view object based on common entity object.
Hi ,
I have
Jdeveloper version - 10.1.3.3.0
Oracle Database - 11g R2
I have a situation where i have to show data from one table in three adf tables on jsf page depending on a flag value in a column in table. For this purpose i have done the following steps
a) Created an entity object on the database table .
b) Created three view objects on this entity object and edited the view object's SQL and included the where clause
WHERE A.USER_PERSONAL_NO = :P_USER_PERSONAL_NO AND
A.AUTH_TYPE = 'LF'
The auth_type cloumn decided in which view object the data will be shown
Now, when i query the data from database by executing the query of these view objects the data is shown correctly in all three view objects. Till here there seems every thing ok
Now , i have to provide the logic to add records in the adf tables for this i have provided add button in action facet of all three tables which are binded to methods in managed bean,
when i add a record in a adf table by add button the new row which is created is shown in all three tables . I cant understand why this is happening , please help me to solve this problem.
How can i make it possible so that the record appears only in that adf table in which the record is added.
The method for adding record is
Row rw = currentAM.getWfRecommAuths().createRow();
rw.setAttribute("UserPersonalNo",this.getQuery_personal_no().getValue());
rw.setAttribute("AuthPersonalNo","");
rw.setAttribute("AuthType","LX");
currentAM.getWfRecommAuths().last();
currentAM.getWfRecommAuths().insertRow(rw);
Please help , thanks in advance.Hi,
have a look at polymorphic view objects
http://download.oracle.com/docs/cd/E21764_01/web.1111/b31974/bcadvvo.htm#CEGDCCCB
Frank
Maybe you are looking for
-
How to get first Reference from a Mail header?
One of the fields that may appear in an email message header is "References." I need to get the first item (which is a Message ID) in that field. However, when I try the following script for a message that has one or more IDs in References: <pre styl
-
Trying to restore from PC, after big NSW storm
Apple TV Gen 3 not working after storm. Tried to hold down menu button and down button, got nothing, apple logo flashed on tv then nothing. Trying to do restore from PC. itunes, picked up unit, and it says it is downloading the software, I have a sta
-
Put report .rdf file and .xml customization
hi frnds, where can i keep .rdf file and .xml file (for customization)? shall i keep on application server? now, to generate report i've written one script ...where can i keep this? -bhavin
-
I have an Apple Extereme router set up and want to buy speakers to play my iTunes from both my Mac ann iPhone wirelessly. Are there some speakers with "built-in" devices to connect to my network, or will I need another Apple Express for any speaker I
-
Photoshop CS6 (extended) Video card minimum requirements.
Can you tell me if my video card is adequate for using the 3D feature in CS6 Extended? The 3D tools don't seem to work. I get the message below. Do I need an updated video card or driver? Let me know if you need more information. Thank You.