Rows in to columns
Hi,
I have there tables SPRIDEN , GZRDUPS , SPBPERS. which has SPRIDEN has first_name and last_name. SPBPERS has ssn and spbpers_birth_date.
GZRDUPS has two pidms there are Pidm1 and pidm2. Pidm1 has good ids and pidm2 has bad ids.
create table GZRDUPS
GZRDUPS_PIDM_1 NUMBER(8) not null,
GZRDUPS_PIDM_2 NUMBER(8) not null)
create table SPBPERS
SPBPERS_PIDM NUMBER(8) not null,
SPBPERS_SSN VARCHAR2(15 CHAR),
SPBPERS_BIRTH_DATE DATE)
create table SPRIDEN
SPRIDEN_PIDM NUMBER(8) not null,
SPRIDEN_LAST_NAME VARCHAR2(60) not null,
SPRIDEN_FIRST_NAME VARCHAR2(60 CHAR))
insert into GZRDUPS values (1050448,55663);
insert into GZRDUPS values (1050237,56563)
insert into SPRIDEN values (1050448,peter,keane)
insert into SPRIDEN values (55663,peter,DO Not Use)
insert into SPRIDEN values (1050237,SARA,Hana)
insert into SPRIDEN values (56563,SARA,Do Not Use)
insert into SPBPERS values (11111,9/14/1963)
insert into SPBPERS values (222222,11/22/1968)
Select query which i wrote is :
select max(decode(GZRDUPS_PIDM_1,'&a',a.spriden_first_name)),
max(decode(GZRDUPS_PIDM_1,'&a',a.spriden_last_name)),
max(decode(GZRDUPS_PIDM_1,'&a',c.spbpers_ssn)),
max(decode(GZRDUPS_PIDM_1,'&a',c.spbpers_birth_date)),
max(decode(b.GZRDUPS_PIDM_2,'&b',a.spriden_first_name)),
max(decode(b.GZRDUPS_PIDM_2,'&b',a.spriden_last_name)),
max(decode(b.GZRDUPS_PIDM_2,'&b',c.spbpers_ssn)),
max(decode(b.GZRDUPS_PIDM_2,'&b',c.spbpers_birth_date)),
from SPRIDEN a,
GZRDUPS b,
SPBPERS c
where (a.spriden_pidm = b.GZRDUPS_PIDM_1 or
a.spriden_pidm = b.GZRDUPS_PIDM_2)
and (c.SPBPERS_PIDM = b.GZRDUPS_PIDM_1)
and (b.GZRDUPS_PIDM_1 = '&a'
or b.GZRDUPS_PIDM_2 = '&b')
and spriden_change_ind is NULL
group by a.spriden_first_name,c.spbpers_ssn,c.spbpers_birth_date;
I am getting output like this:
peter||DO Not Use||11111||9/14/1963 SARA||Do Not Use||222222||11/22/1968
peter||keane||11111||9/14/1963 SARA||Hana||222222||11/22/1968
I need output like this:
<<----------------------bad id------------------->><<----------------- Good id-------->><<-------------- bad id----------------------->> <<-----------Good id------------->>
peter||DO Not Use||11111||9/14/1963||peter||keane||11111||||9/14/1963||SARA||Do Not Use||222222||11/22/1968||Sara||H||222222||11/22/1968
Thanks in advance..
Edited by: user10285804 on Apr 26, 2011 6:32 PM
Instead of messing up the forums posting duplicate version of the same question
Re: SQL Query help needed
It would be better if you spent your time reading the FAQ instead.
SQL and PL/SQL FAQ
Paying particular attention to *2. How do I ask a question on the forums?*
SQL and PL/SQL FAQ
*2) Thread Subject line*
Give your thread a meaningful subject, not just "help please", "Query help" or "SQL". This is the SQL and PL/SQL forum.
And also the sections on Sample Data, Expected Output and *Formatting with {noformat} {noformat} Tags*
Similar Messages
-
How to get multiple records in one row and different column
Hi All,
I am using oracle database 11g
and i have a two tables table_1, table_2
table_1 having columns
emp_no
first_name
middle_name
last_name
email
and table_2 having columns
emp_no
phone_type
phone_number
and having entires
emp_no phone_type phone_number
1001 MOB 9451421452
1001 WEMG 235153654
1001 EMG 652341536
1002 MOB 9987526312
1003 WEMG 5332621456
1004 EMG 59612356
Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
emp_no first_name middle_name last_name email mobile officeno
1001 mark null k [email protected] 9451421452 235153654
1002 john cena gary [email protected] 9987526312 null
1003 dany null craig [email protected] null 5332621456
1004 donald finn sian [email protected] null null
can i have any inputs to achive this???
Regards
$sidFrank Kulash wrote:
sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
with table_1 as (
select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
select 1002,'john','cena','gary','[email protected]' from dual union all
select 1003,'dany',null,'craig','[email protected] null' from dual union all
select 1004,'donald','finn','sian','[email protected]' from dual
table_2 as (
select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
select 1001,'WEMG',235153654 from dual union all
select 1001,'EMG',652341536 from dual union all
select 1002,'MOB',9987526312 from dual union all
select 1003,'WEMG',5332621456 from dual union all
select 1004,'EMG',59612356 from dual
SELECT *
FROM table_1 t1
JOIN table_2 t2 ON t1.emp_no = t2.emp_no
PIVOT ( max(t2.phone_number)
FOR t2.phone_type IN ( 'MOB' AS mob
, 'WEMG' AS wemg
FOR t2.phone_type IN ( 'MOB' AS mob
ERROR at line 19:
ORA-01748: only simple column names allowed hereYou need to:
with table_1 as (
select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
select 1002,'john','cena','gary','[email protected]' from dual union all
select 1003,'dany',null,'craig','[email protected] null' from dual union all
select 1004,'donald','finn','sian','[email protected]' from dual
table_2 as (
select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
select 1001,'WEMG',235153654 from dual union all
select 1001,'EMG',652341536 from dual union all
select 1002,'MOB',9987526312 from dual union all
select 1003,'WEMG',5332621456 from dual union all
select 1004,'EMG',59612356 from dual
table_3 as (
select t1.emp_no,first_name,middle_name,last_name,email,
phone_type,phone_number
FROM table_1 t1
LEFT JOIN table_2 t2 ON t1.emp_no = t2.emp_no
SELECT *
FROM table_3
PIVOT ( max(phone_number)
FOR phone_type IN ( 'MOB' AS mob
, 'WEMG' AS wemg
EMP_NO FIRST_ MIDD LAST_ EMAIL MOB WEMG
1004 donald finn sian [email protected]
1003 dany craig [email protected] null 5332621456
1001 mark k [email protected] 9451421452 235153654
1002 john cena gary [email protected] 9987526312
SQL>SY. -
Converting each row in a column to an XML
Hi everyone,
Using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
I have a table where there is a comments column which is VARCHAR2. That column contains string data in the form of XML tags.
Like for eg. *<tag_name attr_name="10"/>* (sorry cant provide the exact values as I'm not allowed to)
There are many such rows. Now I want to use these strings and operate on them as XML like using XPath to find certain attributes etc.
I tried using the extract function and to use it i need a XMLType object. So I tried to create one using the XMLType() constructor.
But it gives me the error ORA-19032: Expected XML tag , got no content
When I looked it up on the net, I found that this error number doesn't correspond to the error message that I'm getting. The error msg found on the internet was Expected XML tag string got string
I used this query
SELECT XMLType (<column>) FROM <table>;But when I modified it (based on someone's hunch) to
SELECT XMLType (<column>)
FROM <table>
WHERE ROWNUM <= 1;The query worked fine. Like it can take only one row.
I also tried like this
SELECT XMLType ('<tag_name attr_name="10"/>')
FROM DUAL;This too worked fine.
So finally this has left me completely confused. Is there a way to convert every row in a column to an XMLType object so that I can use the extract function to gather information about it.
For the time being I have used REGEXes to write the code. But having the flexibility of xml would be better.
Any help would be appreciated.
Regards,
Arijit
Edited by: Arijit Kanrar on May 23, 2013 5:27 AMArijit,
The error message is correct. What you found is merely the generic message with string placeholders.
The error message is also pretty self-explanatory : you can't pass an empty string (NULL) to the XMLType constructor.
SQL> select xmltype('') from dual;
ERROR:
ORA-19032: Expected XML tag , got no content
ORA-06512: at "SYS.XMLTYPE", line 310
ORA-06512: at line 1
no rows selectedYou have to either add a WHERE clause to filter out NULL columns, or use a CASE statement to only convert strings that aren't empty :
SELECT XMLType (<column>)
FROM <table>
WHERE <column> IS NOT NULL ;
SELECT CASE WHEN <column> IS NOT NULL THEN XMLType (<column>) END
FROM ...And do not use EXTRACT if you want to access scalar values, use EXTRACTVALUE instead :
SQL> select extractvalue(xmltype('<tag_name attr_name="10"/>'), '/tag_name/@attr_name') from dual;
EXTRACTVALUE(XMLTYPE('<TAG_NAMEATTR_NAME="10"/>'),'/TAG_NAME/@ATTR_NAME')
10 -
On ALV report in1 column I want to put Icon on every row of that column.
On ALV report there is 1 column I want to put Icon on every row of that column.That ALV program uses object oriented concept all class and methods.
I want to use that icon on that row. That icon name is ICON_OKAY
In my program when I assign values to internal table at that time I am assigning that ICON_OKAY value to that row as follow.
Itab-
Itab-icon = ICON_OKAY.
Append itab.please follow below procedure to display icon in ALV
1) In corresponding fieldcatelog entry do
fieldcatalog-icon = 'X'
2) While filling the internal table fill the corresponding key value of icon , for example ICON_OKAY value is '@0V@' so statement would be
Itab-icon = '@0V@'
to get list of corresponding key for icon open include <ICON> in se38 -
Different number of rows for different columns in JTable
hi
I need to create a JTable with different number of rows for different columns...
Also the rowheight should be different in each column...
say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
how do I do this ??
can anybody send me some sample code ?????
thanx in advanceHow about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
Or you could leave the extra columns null/blank.
You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
It would help if you were more specific about how you wanted it to appear and behave. -
How to get fourthly row (row4) first column value (col1) in matrix
Hi to all,
In FMS, how to get fourthly row (row4) first column value (col1) in matrix in document.
select $[$38.1.4]
But it display the first row
Please give me hint.
Thank youHi Eric,
FMS may only apply to current row. There is no way to get any other fixed row.
Thanks,
Gordon -
Applying table scroll bar for only table rows with table columns fixed.
hi oa gurus,
i had implemented table scroll bars using oarawtextbean , there is no problem in vertical and horizontal scroll bar working its working fine. but the requirement is i need to scroll only the table rows with table columns fixed. so , how to achieve the table scroll for only table datas neglecting table headers.
the code for vertical and horizontal bars scroll is like this,
OARawTextBean ors = (OARawTextBean)webBean.findChildRecursive("raw1");
ors.setText(div id=tabledivid style=height:500px;width:100%; overflow:auto>);
OARawTextBean ore = (OARawTextBean)webBean.findChildRecursive("raw2");
ore.setText("</div>");
where raw1 and raw2 are rawtextbean created above and below of the table . but i dont know hoow to apply this only for table rows neglecting table columns , can anybody give any ideas.
pelase this is very urgent , can u help me in this regards
thanks
Edited by: user630121 on Sep 29, 2008 5:17 AM
Edited by: user630121 on Sep 29, 2008 5:18 AMhi,
I have a similar task to do... Only to apply scrollbar at the table level.
I tried using the above mentioned but I am facing Null Pointer Exception..
Please explain about raw1 and raw2
Rahul -
Count the no. of rows in a column
I want to count the no. of rows in APR_QTY column that are not equal to zero.
SELECT DISTINCT
SUPP_NAME,
ITEM_NAME,
(CASE WHEN BH_CAL_PERIOD=4 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)APR_QTY,
(CASE WHEN BH_CAL_PERIOD=4 THEN BI_RATE ELSE 0 END)APR_RATE,
(CASE WHEN BH_CAL_PERIOD=5 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)MAY_QTY,
(CASE WHEN BH_CAL_PERIOD=5 THEN BI_RATE ELSE 0 END)MAY_RATE,
(CASE WHEN BH_CAL_PERIOD=6 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUNE_QTY,
(CASE WHEN BH_CAL_PERIOD=6 THEN BI_RATE ELSE 0 END)JUNE_RATE,
(CASE WHEN BH_CAL_PERIOD=7 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUL_QTY,
(CASE WHEN BH_CAL_PERIOD=7 THEN BI_RATE ELSE 0 END)JUL_RATE
FROM
OM_SUPPLIER,
OM_ITEM,
OT_BILL_HEAD,
OT_BILL_ITEM,
OT_BILL_ITEM_TED
WHERE BI_BH_SYS_ID = BH_SYS_ID
AND SUPP_CODE = BH_SUPP_CODE
AND ITEM_CODE = BI_ITEM_CODE
AND BH_SYS_ID = ITED_H_SYS_ID
AND BI_SYS_ID = ITED_I_SYS_ID
AND BH_TXN_CODE='SBRLRAW'
GROUP BY BH_CAL_PERIOD,BH_TXN_CODE,SUPP_NAME,ITEM_NAME,BI_RATE,BI_QTY,BI_QTY_LS
ORDER BY ITEM_NAME
Message was edited by:
yogeshylSelect sum(decode(apr_qty,0,0,1)) as cnt_apr_qty
from ... -
How can we fix images and String in a perticular row's second column in JTa
Hi,
I have to design a window in which there is a table I have to set the some row's second column data with images and text data both and some row contan only text data Please help me on it .There is two column and 5 row in my table.
Thanks in advance,
anum[url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender]Using Editors and Renderers
You will need to create a custom renderer to display both an image and text. Renderers are assigned to a column. If you require different renderers for a given row in a column then you will need to override the getCellRenderer(...) method to return a renderer for the specific row. -
How to get difference between two rows for a column field?
hi, all,
Could anyone show me what query statement is to get the difference betweem two rows for two column fields?
The tables and its records are like this:
id, begin, end
p1 21 30
p2 45 60
p3 120 150
I would like to have the query result like this
id, diff
p1 15 --- which is 45 minus 30
p2 60 --- which is 120 minus 60
and so on...
thank you in advance.
RaffyYou can use the LAG function to access values from previous rows:
with q as (select 'p1' id, 21 v_start, 30 v_end from dual
union all
select 'p2', 45, 60 from dual
union all
select 'p3', 120, 150 from dual)
select id, v_start, v_end, v_start - lag (v_end, 1, 0)
over (order by id) v_diff from q
ID,V_START,V_END,V_DIFF
p1,21,30,21
p2,45,60,15
p3,120,150,60
See the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions075.htm -
Is it possible on 10.2.0.4 to pivot 1 row into 2 columns without any pipelined function?
COL1_NAME | COL2_NAME | COL3_NAME
VAL1 | VAL2 | VAL3into:
NAME | VALUE
COL1_NAME | VAL1
COL2_NAME | VAL2
COL3_NAME | VAL3Sure:
with a_tab as (select 1 id, 'val1' col1, 'val2' col2, 'val3' col3 from dual union all
select 2 id, 'val11' col1, 'val12' col2, 'val13' col3 from dual),
-- end of mimicking main table data
dummy as (select 1 id from dual union all
select 2 id from dual union all
select 3 id from dual)
select a_tab.id,
decode(dummy.id, 1, 'col1',
2, 'col2',
3, 'col3') col_name,
decode(dummy.id, 1, a_tab.col1,
2, a_tab.col2,
3, a_tab.col3) col_value
from a_tab,
dummy
order by id, col_name;
ID COL_NAME COL_VALUE
1 col1 val1
1 col2 val2
1 col3 val3
2 col1 val11
2 col2 val12
2 col3 val13 This uses a method of cartesion product to replicate the rows in the main table so there's one row for each of the columns you want to unpivot (in our case, 3 cols, so the dummy table has 3 rows), then using decode to work out which column is displayed on which row. -
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. -
I have 105 rows with alternating columns of No. sold
I have 105 rows with alternating columns of No. Sold and Amount Sold, for six different dates. I want the two totals columns on the right to sum every other column for the Total No. Sold and the same but one over for Total Amount Sold. I know how to do this for a single row, as I have done for the last totals row. How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?
rogerfrombellingham wrote:
... I know how to do this for a single row, as I have done for the last totals row. How could I do the formula for all rows without entering it for each one, or if that is not possible, maybe I could copy the formula in some way to make it easier?
Yes, Roger, you can easily copy those formulas for all the rest of the 105 rows.
Select the two totals cells, click on the little circle in the lower right corner of the selection and drag it to the bottom.
Jerry -
How to suppress row when one column has zero using condition
Hi Experts,
How do I suppress row when one column has zero.
I read it is possible using conditions.
How ?
Thankyou.Check this
1. for Query Properties, go to the Display tab and Supress Zeros is "Active"
2. select the Structure, right-click, select Properties, then click "on" Also Use Zero Suppression for Structure Elements
http://help.sap.com/saphelp_nw04/helpdata/en/a4/dd3841d132d92be10000000a1550b0/frameset.htm
Hope it Helps
Chetan
@CP.. -
DataGrid alternating row colors per column
Is there a way to set different alternating colors to each
column in a DataGrid. I have a datagrid where I want two of the
columns to have different alternating row colors, one column (red
and light red) and the other (green and light green).
Many thanksYou can simply set the DataGridColumn property to the
approprate colors.
ex.
<mx:DataGrid y="0" x="0" width="100%">
<mx:columns>
<mx:DataGridColumn id="col1" backgroundColor="0x640000"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0xFF0000"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0x006600"
dataField="col1"/>
<mx:DataGridColumn id="col1" backgroundColor="0x33CC33"
dataField="col1"/>
</mx:columns>
</mx:DataGrid>
or you can use the setStyle:
col1.setStyle("backgroudColor", 0x640000) -
How to create 2D array with 3 rows and unlimit column?
how to create 2D array with 3 rows and unlimit column?
Here are images of what I described in my previous post
Message Edited by JoeLabView on 11-14-2007 07:56 AM
Attachments:
2D-array_code.PNG 7 KB
2D-array_values.PNG 13 KB
Maybe you are looking for
-
I have had my ipod touch 4th generation for a few years now and all of a sudden it wont connect to wifi. Even though it says im connected it doesn't work. It has a tick beside the name and everything! Also it has three bars saying im fully connected
-
Photoshop CS keeps crashing since Tiger upgrade
Photoshop CS keeps crashing when saving files since we upgraded to 10.4.5 Tiger. Everything was working fine under 10.3.9 Panther. Is that a known issue? Thanks!
-
Schema validation in WL 9.1
I am using WL 9.1 and i get the following errors while validating the schema [webddr] XMLParser - file:///C:/dev/artfrank_Core_4_2_int/WFX_Core/core/stagi ng/resource/auth-service-war/WEB-INF/weblogic.xml (L2,C61): Document root elemen t "weblogic-we
-
I have created a ZTABLE- having amount field and currency/qunatity field as WAERS and tcurc as reference table. Created a structure where i created zwaers as field and currency and quantity fields as ZWAERS and my structure name as reference table--i
-
DISK FULL WARNING, WHY?
I was getting the message "scatch disk full" so I went and got a brand new external drive. In Preferences, the only box I have checked for CS5 to use as the scratch disk is the new external drive. That the external drive is solely being used by CS5 h