Multiple row data in a single row
I have a table like the following:
AGREEMENT_ID SERVICE_CODE SERIAL_NO
22 CV CE095F0011007884F
22 HS 2509b000121373869
22 NG 2509B000121265554
22 SG 2509B00012120278D
22 SM PAFABM0716140704
22 SN G32X2MI808300348
22 SP CE095F00110045416
22 SV 2509B000121363230
22 SW CE095F00110037377
I would like to have it in the following format
Agreement_id CV HS NG SG SM SN SP SV SW --(These are the columns)
22 CE095F0011007884F 2509b000121373869 2509B000121265554 ....
(This is data)
Need to do it in a single Query....
Want an advice
Regards
Chaitanya.S.S.K
Hi,
SQL> l
1 with tbl as
2 (select 22 id, 'CV' service, 'CE095F0011007884F' serial from dual
3 union all
4 select 22, 'HS','2509b000121373869' serial from dual
5 union all
6 select 22, 'NG','2509B000121265554' serial from dual
7 union all
8 select 22, 'SG','2509B00012120278D' serial from dual
9 union all
10 select 22, 'SM','PAFABM0716140704' serial from dual
11 union all
12 select 22, 'SN','G32X2MI808300348' serial from dual
13 union all
14 select 22, 'SP','CE095F00110045416' serial from dual
15 union all
16 select 22, 'SV','2509B000121363230' serial from dual
17 union all
18 select 22, 'SW','CE095F00110037377' serial from dual
19 union all
20 select 23, 'SW','CE095F00110037377' serial from dual)
21 select id,
22 max(decode(service,'CV',serial)) "CV",
23 max(decode(service,'HS',serial)) "HS",
24 max(decode(service,'NG',serial)) "NG",
25 max(decode(service,'SG',serial)) "SG",
26 max(decode(service,'SM',serial)) "SM",
27 max(decode(service,'SN',serial)) "SN",
28 max(decode(service,'SP',serial)) "SP",
29 max(decode(service,'SV',serial)) "SV",
30 max(decode(service,'SW',serial)) "SW"
31 from tbl
32* group by id
SQL> /
ID CV HS NG SG SM SN SP SV SW
22 CE095F0011007884F 2509b000121373869 2509B000121265554 2509B00012120278D PAFABM0716140704 G32X2MI808300348 CE095F00110045416 2509B000121363230 CE095F00110037377
23 CE095F00110037377
SQL> HTH,
Nicolas.
Similar Messages
-
Obiee report two rows data present in single row
Hi Experts,
I have facing one problem how to reslove this problem let me know.
In DB Table like this.
Sno **** Value1 **** Value2
10 ******** 100 ******* 0
10 **** *** 0 ******* 200
i want to out put Obiee reports like this ?????????
sno ***** value1 **** value2
10 ****** 100 **** 200
How to achive this please tell me any method
i am using obiee 10.1.3.4.1 version (i am try to create report OBIEE answers )
Thanks
Satya
Edited by: satya vardhan on Jul 11, 2011 6:56 PMTry going it by Sno.
If you are using Pivot Table, try changing measures from columns to rows and see. I vaguely remember doing this would address your need
Thanks,
Vinag -
Concatenation of row data into a single row
Hi,
I have table which has the data in the following way.
col1 col2 col3
a 1 one
a 2 two
a 3 three
b 1 dfdf
b 2 sfdhh
c 1 zgdhi want data in the following way.
col1 col2 col3
a 1,2,3 one,two,three
b 1,2 dfdf,sfdhh
c 1 zgdhCan any body help me.
Thanks in advancemay be this will work
WITH tab AS
(SELECT 'A' col1,1 col2, 'one' col3 FROM dual
UNION ALL
SELECT 'A' col1,2 col2, 'two' col3 FROM dual
UNION ALL
SELECT 'A' col1,3 col2, 'three' col3 FROM dual
union all
SELECT 'B' col1,1 col2, 'abc' col3 FROM dual
UNION ALL
SELECT 'B' col1,2 col2, 'defg' col3 FROM dual
UNION ALL
SELECT 'C' col1,1 col2, 'hijcol' FROM dual
union all
SELECT 'C' col1,2 col2,'klm' col3 FROM dual
SELECT col1
, ltrim(MAX(SYS_CONNECT_BY_PATH(col2,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS col2,
ltrim(MAX(SYS_CONNECT_BY_PATH(col3,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',')as col3
FROM ( SELECT col1
, col2,col3
, ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2) AS curr
, ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2) -1 AS prev
FROM tab )
GROUP BY col1
CONNECT BY prev = PRIOR curr AND col1 = PRIOR col1
START WITH curr = 1;
COL1 COL2 COL3
A 1,2,3 one,two,three
B 1,2 abc,defg
C 1,2 hijcol,klm -
Merging multiple rows in to a single row (when rows meet merging criteria)
Hi
I have a scenario to merge multiple rows in to a single rows when the data in those rows fall in merge criteria .Below is how my data is
Now the merging logic for the above rows is , we need to combine multiple rows in to a single row when the data in those rows permits us to do in that way. Simply saying , its like sandwich where we combine multiple things to a single piece.The output for
the above rows should be
Here we combined Row 1 ,2, 3 in to a single row as the data in those rows permits to merge in to single row. But the row 4 cannot be combined to any of those rows because the data in those rows doesn't permits us do a merge ( As the value of the column
JobSource for the row 4 is different from the other rows ) .
My original data has 56 columns , but for readability i kept only 9 columns.
can you please throw some idea on how to achieve this scenario. I know we need to use CTE for achieving this, but i am not able succeed in doing an iteration on multiple rows.
Appreciate your response .Thanks for your reply .
Rule for merging is simple . First of all there is no unique row identifier for each row , the fact table is not having an identity column in the database . I called row 1 , row 2 etc in my post above only to make better explanation of my scenario.
The rule for merge is below.
1) we can combine only when the data in a column for one row is null & the data in same column for the other row is not null . It should also satisfy the condition where the data in other columns should conflict each other.
2) Data for all columns for the merging rows should not be conflicting (i.e. we should not merge the rows when the data in a column is not equal to the same column in the other row
,considering not null value)
Steps in merging the above source data :
1) Consider the case of row 1 and row 2 in the source, we can combine these rows as the data is satisfying the rule 1 for columns (Jobsource,Flight, Package,Update,Iscancelled
,Result, Severity) and columns (JobID and RuleName ) fall under rule 2. we merge these two rows in to a single row and keep in that in the table.
2) Then the resulting row is again merged with the second row which is present above by applying the rule 1 and rule 2 . Below would be output of merge operation.
Now there would be only two rows in the output . But these rows cannot be merged as the data doesn't satisfy the merge rules 2 . As Jobsource for the row 1 in the above output is "PresubmissionSource" which is not equal
to "PostSubmission" jobSource which is in row 2. So these two rows are left unmerged .So the above two rows would be the output of merge operation on my source data.
This process has to be repeated for all the rows in the table. As of now my table as 92 Million rows with 56 columns which need to be considered for merging rows. I replicated my scenario in 9 columns and 4 rows to understand better. -
Display of data in a single row
Hi
Here is my query:
SELECT
--Element Classification Details:
pec.CLASSIFICATION_ID,
pec.classification_name,
pec1.classification_id "Sub Classification Id",
DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions',
'Others Voluntary Deductions', 'Other Deductions',
'Personal Deductions', 'Personal Deductions',
'Personal Voluntary Deductions', 'Personal Deductions',
'Car Loan Deductions') "Sub Classification",
pec1.parent_classification_id,
scr.sub_classification_rule_id,
--Element Details:
pet.element_name, pet.element_type_id, pet.reporting_name,
DECODE(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
--Run Result Details:
prr.run_result_id,
TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)) "Amount",
piv.NAME "Input Value",
--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
AND paa.ASSIGNMENT_ID = '560'
I needed to display the amounts as separate columns pertaining to different elements or rather different sub classification of the elements
This is the final expected result for the report:
Employee Personal Deductions PD Amount Other Deductions OD Amt
XYZ Element1 00000.00 Element3 0000.00
Element 2
Car Loan Deductions CLD Amt Total Deductions (Total of all three)
Element4 00000.00 00000000.00
Here Personal Deductions, Other, Car Loan etc. are grouping of elements (sub classifications)
I have used MAX function to display the results as separate columns like this:
SELECT
--Run Result Details:
prr.run_result_id,
MAX(DECODE(pec1.classification_name, 'Personal Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal Deductions",
MAX(DECODE(pec1.classification_name, 'Personal Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal V Deductions",
MAX(DECODE(pec1.classification_name, 'Other Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Other Deductions",
MAX(DECODE(pec1.classification_name, 'Others Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Others V Deductions",
MAX(DECODE(pec1.classification_name, 'Car Loan Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Car Loan Deductions"
/*--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"*/
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv
/*hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp*/
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
/*AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
--and pet.element_NAME like 'IVTB%'
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE*/
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
--and paa.PRIMARY_FLAG like 'Y%'
/*AND paa.payroll_id != 0
AND paa.pay_basis_id != 0*/
GROUP BY
prr.run_result_id
However, the fact is that my each element_type_id has each run_result_id, which means 1 element has 1 run result id. Thus, I cannot display the data in a single row.
Can someone guide me on this? How can I display the data for an employee as a single row?
Thanks and regards,
AparnaSELECT EMP_ID,
Sum(Decode(DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions','Others Voluntary Deductions', 'Other Deductions'),'Other Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Other deduction',
sum(Decode(DECODE(pec1.classification_name,'Personal Deductions', 'Personal Deductions', 'Personal Voluntary Deductions', 'Personal Deductions'),'Personal Deductions'),TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Personal deduction',
sum(DECODE(pec1.classification_name,'Car Loan Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Car deduction'
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
I hope this may help!
Brijesh -
PL/SQL muliple row insert for a single row
I need to insert multiple rows based on a single row record. Below are the table structures and sample data
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20))
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('hello','asd','fgh','ert',null);For the above record in table TEST_SAMPLE, three records have to be populated\inserted into table TRANSACTION. In PL/SQL
stored procedure i am inserting records to TRANSACTION when ATTR_1 or ATTR_2 or ATTR_3 or ATTR_4 is not null.
Please help me to find a better way for the above insert to table TRANSACTION?Thanks for helping me here. For the sample record in table TEST_SAMPLE i mentioned above three records need to be inserted in table TRANSACTION. you have this, or?
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TEST_TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20));
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 1','asd','fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 2',null,'fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 3','asd',null,'ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 4','asd','fgh',null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 5','asd',null,null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 6',null,null,null,null);
commit;
insert into TEST_TRANSACTION
select NAME,
ATTR_1
from TEST_SAMPLE
where ATTR_1 is not null
union all
select NAME,
ATTR_2
from TEST_SAMPLE
where ATTR_2 is not null
union all
select NAME,
ATTR_3
from TEST_SAMPLE
where ATTR_3 is not null
union all
select NAME,
ATTR_4
from TEST_SAMPLE
where ATTR_4 is not null
commit;
select *
from TEST_TRANSACTION
order by 1;
Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.
10 rows created.
Commit complete.
NAME ATTR
record 1 asd
record 1 fgh
record 1 ert
record 2 fgh
record 2 ert
record 3 ert
record 3 asd
record 4 fgh
record 4 asd
record 5 asd
10 rows selected. -
Multiple pages that edit a single row
I have searched on tabs and editing a single row using multiple pages and I am confused. I don't want to use java as I am trying to not learn that too...
What I am trying to do sounds like it has been explained before but let me do this again...
I have a record that is too large to fit on a single screen. This makes for a cumbersome entry process. The record is actually broken into four "logical" chunks. Main, Sub1, Sub2 and Sub3.
I have made a list that will allow the record to be selected and call the first logical page... L1.
I have made tabs that show all the pages and allow me to navigate between them quickly.
When I get to L1 all the data is there. I may not change any data on that page and go directly to L2 through L4. However the record is not brought forward onto those pages. So the pages are not related (and I don't have the terminology right I know :) and I could "link" the pages. So here is what I would like the application to do;
1. Display a list and allow the user to select the record to edit.
2. Upon edit go to the first page (tab).. this works
3. Allow the user to select a tab and the page displays the data for the record selected
4. Allow the user to complete the edits and save the record. Upon save the user is returned to the list in step 1.
I was thinking there are several ways to do it... but I was hoping someone could save me a bunch of trial and error (emphasis on the error) ...
1. When navigating off the page save the record, pass the key and re-read the record... ugly huh?
2. Pass all the session data for the record over to the next screen. Is that possible? e.g pxx_field1 = pyy_field1
The the question was does a template with two level tabs keep the record data between tabs?
Any help is greatly appreciated.
SamI think this works... kinda
1. I have a "list" that allows the selection of the item to edit.
2. That list opens a page that is the "header" page for a tab set.
3. Each page in the tab set uses the same "ID" to read the record and display the columns. That is how it would work if the list called each individual page.
4. I modified the "slave" tabs to have the "ID" of the "header" page.
This displays the correct data on each page. And it looks like the "apply changes" button saves the changes on the page.
Caveats inlclude (I think as I haven't done exhaustive testing"
1. "apply changes" must be done at each page where there were changes or they would be lost.
2. The first dispaly of the page is blank. Clicking on the tab a second time displays the data. This is true if it is the first time a user selects a record in a session (the "slave" tabs are blank) or if it is a subsequent record update (the "slave" tabs have the last records data.
Thoughts... is this really boring to everyone but me?
Sam -
How to display mutliple rows of database data in a single row
We are using XML Publisher 5.6.2. We have a requirement, where we need to display a multiple database rows for a single column in a single row.
Basically say a database column has 5 rows
A1
A2
A3
A4
A5
We want to display in the output in a single cell as
A1 A2 A3 A4 A5
Thanks,
- Vasu -Look at this blog,
http://blogs.oracle.com/xmlpublisher/2007/05/24#a325 -
How to store array of data into a single row of table ,using any of Stmts
HI Friends,
Based on my requirements ,i have retrived a set of data from a XXX.jsp page using a request.getParameter() and stored into single dimenssional array . Now i am paassing that array to JAVA class to store a into some table .
In JSP page users can add text boxes dynamically based on his intrest then those attributes will store in table .it means table attributes are not conatant , it table attributes may change at any time when user adds any textboxs or any fields on JSP page ....thats my module ..
Now i wanted to store all array of data into Table in a single row .......thats is my requirements .
How can we use prepareStatement and Statement to store array of results intoo table row ...on each iteration i wanted to store array of results into table atributes ..It means entire array of results should to into table row at time .....coule any one write sytax ,how we do this...
could any one suggest me stps that i can impliment ......?....please reply ASAPWell ..you code can be works for constant number of attributes in table .oopss here my requirement is table attributes not fixed ,we cant put constant number of place holder(? ) in a statement ,because those are not fixed ,
Let me explain here :
i am doing in that way only. As i mentioned you Table attributes are not constant .It may very if users add any fields dynamically on JSP page .If users have option to add any text box on Jsp page ,then that attribute will store in table as a attribute .
Now i amable fetching the all dyamic form data and stored in a Result Array below ...in this iteration all form result data are from jsp page as suggestion form ,it should stored in table in single row on corrsponding attribtes ......next time when users fills FROM ,then those data i am fetching and storing in a Result Array as below and need to store in corrsponding table attributes in a single row ....
for(int i=0;i<result.length;i++)
System.out.println(result);
pst3=connection.prepareStatement("insert into *emprecord* values(?)");
if(!result[i].equals(""))
System.out.println(result[i]);
pst3.setString(1,result[i]);
pst3.executeUpdate();
Thnks in advance ....let me know the the way we can store dynamic form data into dyanamic table ... -
To make Three row values in a single row
Hi,
Below is the Table Format i have.
Here for the first Mail_ID i have 3 mail addresses.similarly for second ID too.
I want First three rows to be in a single row.and so on...
Plz help in doing this.
Thanks
DeepaDeepa,
Check if this helps.. Does dynamic conersion of data to columns ..
--Your Email table
create table #temp (mailid int,to_mail varchar(100))
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 3,'[email protected]'
--Constructing a temp table to hold data with row_numbers
select *,row_number() over(partition by mailid order by to_mail) as rn
into #t
from #temp
--declaration of variables
declare @n int,@list varchar(max),@sql nvarchar(max)
set @n=(select max(rn) from #t)
--Population of list to form the dynamic query
;with cte
as
select cast(',[email1]' as varchar(max)) as ch,1 as num
UNION ALL
select cast(ch+',[email'+cast((num+1) as varchar(100))+']' as varchar(max)) as ch,num+1 as num
from cte where num<@n
select top 1 @list=stuff(ch,1,1,'')
from cte
order by num desc
--Formulating the complete dynamic query
set @sql='
select mailid,'+@list+'
from
select mailid,to_mail,''email''+cast(rn as varchar) as emailnum from #t
) tab
PIVOT
max(to_mail) for emailnum in ('+@list+')
) pvt'
exec sp_executesql @sql
--clean up
drop table #t
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Merge two rows & show in a single row in table results
Hi, I need to merge 2 rows having 3 columns in a single row in table view
The cols are currently shown as :
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000
20000
Revenue is a single column with revenue for diffreent Period.
10000 is for May
20000 is for April
Project NO for both are same, just the periods are different. if I am not displaying Period i need to merge the 2 rows & show as
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000 20000
Please let me know how we can acheive this??
thanx
Pankaj123123 is the project number..
the above is not getting displayed properly....as the blank spaces are removed...
Please consider this -
Using sql load insert multiple fields data into a single column in database
Hi ,
I have my log file in sun OS box something like this
=======
(07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
(07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
(07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
=============
I am trying to insert the data into oracle data base as follows.
=============================
column1 : (07/29/2009 00:02:24.467)
column2 : 367518
column3 : (07/29/2009 00:02:26.214)
column4 : 949384011
===========================
Can anyone help me with the control file format?
someone suggested me the code below.
==========
LOAD DATA
INFILE 'D:\work\load.txt'
INTO TABLE sample
(col1 POSITION(02:24) char,
col2 POSITION(27:32) INTEGER EXTERNAL,
col3 POSITION(35:57) CHAR,
col4 POSITION(60:68) INTEGER EXTERNAL
===========
but this works only for the fixed length data? Please helpuser11744904 wrote:
Hi ,
I have my log file in sun OS box something like this
=======
(07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
(07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
(07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
=============
I am trying to insert the data into oracle data base as follows.
=============================
column1 : (07/29/2009 00:02:24.467)
column2 : 367518
column3 : (07/29/2009 00:02:26.214)
column4 : 949384011
===========================
Can anyone help me with the control file format?
someone suggested me the code below.
==========
LOAD DATA
INFILE 'D:\work\load.txt'
INTO TABLE sample
(col1 POSITION(02:24) char,
col2 POSITION(27:32) INTEGER EXTERNAL,
col3 POSITION(35:57) CHAR,
col4 POSITION(60:68) INTEGER EXTERNAL
===========
but this works only for the fixed length data? Please helpIs the requirement to load all data in a single column or multiple columns? The thread subject and body are conflicting. -
Hi All
I have facing the Single row sub query Error . I tried to resolve , but my condition not working .can please any help to rewrite the query (sub query)
SELECT DISTINCT wdlsv.serial_number
,wdlsv.date_shipped
,wdlsv.inventory_item_id
,wdlsv.organization_id
,wdlsv.lot_number
,(select distinct engine from xxtc_tr_pr_open_data where chassis=wdlsv.serial_number and rownum=1
union
select distinct replace(replace(attribute11,'*',''),' ','')
from xxtc_chassis_scanout_details
where serial_number=wdlsv.serial_number
and operation_line_code ='CHASSIS') "ENGINE_NO"
,oola.attribute1 oh_excise_no
,msi.attribute16 vehicle_type
,bbom.attribute2 model_no
,xxst.tariff_code tariff_code
,substr(xxst.color_type,1,1) color_type
,(SELECT TO_CHAR(trunc(rt.transaction_date),'RRRRMMDD')
FROM rcv_transactions rt,
rcv_shipment_lines rsl,
rcv_shipment_headers rsh
WHERE rsh.shipment_header_id=rsl.shipment_header_id
AND rt.shipment_header_id=rsl.shipment_header_id
AND rsl.attribute1=wdlsv.lot_number
AND rt.organization_id=wdlsv.organization_id
AND rt.organization_id=rsh.organization_id
AND ROWNUM<=1
union
select distinct to_char(xxtp.indent_import_date,'RRRRMMDD')
from xxtc_tr_pr_open_data xxtp
where xxtp.chassis = wdlsv.serial_number) "CKD_IMPORT_DATE_YEAR"
,to_char(xxtp.indent_import_date,'RRRRMMDD') import_date
FROM WSH_DELIVERY_LINE_STATUS_V WDLSV
,oe_order_headers_all ooha
,oe_order_lines_all oola
,mtl_system_items_b msi
,bom_bill_of_materials bbom
,xxtc_sales_tax_cal xxst
WHERE 1=1
AND PICK_STATUS = 'C'
AND delivery_status = 'CL'
AND ooha.header_id = wdlsv.source_header_id
AND ooha.header_id = oola.header_id
AND oola.line_id = wdlsv.source_line_id
AND msi.inventory_item_id = wdlsv.inventory_item_id
AND msi.organization_id = wdlsv.organization_id
AND bbom.assembly_item_id = wdlsv.inventory_item_id
AND bbom.organization_id = wdlsv.organization_id
AND xxst.inventory_item_id = wdlsv.inventory_item_id
AND xxst.organization_id = wdlsv.organization_id
and upper(msi.attribute15) not like 'SUB%'
AND WDLSV.SERIAL_NUMBER IS NOT NULL;
Regards
SanjayThis forum is for questions about working with SQL*Developer. The title is "SQL Developer (Not for general SQL/PLSQL questions)" and yours is a general SQL question. You should get a better answer by re-posting in the SQL and PL/SQL forum in the Oracle Database section. Please mark this tread as answered and re-post there.
-
Writing multiple port data report into single excel file
I'm working on a STTE automation of an power management unit in which data's from 6 different channels are received from the unit which has to be tested and then verified and co-related with the digital and analog inputs given by the user. So my question is finally how to write all dese six channel's data to a single excel file with multiple work sheets..... Like channel-1 one in sheet1,ch-2 in sheet2 so on.... (these data's from 6 different are received from 6 different serial communication port.)
pls guide how to forward in the final report generation for abv mentioned requirement in labviewAs nyc mentioned you will have to use ActiveX if you want to do exactly what you discribed but if you're new to LabVIEW that can be a big step.
In the VI you posted you write your data to xls file but the fact is that you use the write to text file function, so in the end your file is just a simple text file, and of course Excel can open this type of file.
Maybe you could have your VI to write txt files and then have another bit of code that would transfert the data in each text file to differnt worksheet in a Excel file.
Or maybe another option would be to write all your data to the same TDMS file (on channel per port) and then use the TDMS Excel Add in to generate an Excel file from the TDMS.
Feel free to ask more questions :-o
When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!" -
JSF-Data Table displaying all data in a single row
Hi Guys,
Im new to JSF, im trying to display the details from a List in a data table, but all the details are getting displayed in a single cell instead of displaying as rows, can someone help me with this problem?You need post your code so that we can view it.
This is an example of dataTable
<h:dataTable border="1" id="qresults" cellpadding="4" styleClass="subjectQRTbl" cellspacing="4" value="#{wormingList.worming}" var="bbr" first="#{wormingList.firstRowIndex}" rows="#{wormingList.noOfRows}" rowClasses="evenRow,oddRow">
<h:column>
<f:facet name="header">
<h:outputText escape="false" value="Vaccination Date" />
</f:facet>
<h:commandLink id="locnum" action="#{appAction.getWormingRecord}" title="Update Worming History Record">
<h:outputText value="#{bbr.dateWormed}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<f:param name = "recordId" value ="#{bbr.id}" />
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header" >
<h:outputText escape="false" value="Vaccination Type" />
</f:facet>
<h:outputText value="#{bbr.type}" styleClass="readOnly" />
</h:column>
<h:column>
<f:facet name="header" >
<h:outputText value="Vaccination Dosage" />
</f:facet>
<h:outputText value="#{bbr.dosage}"styleClass="readOnly"/>
</h:column>
</h:dataTable>
Hope this helps
Maybe you are looking for
-
How to install korean language on my BB Z10???
Dear users, i recently bought BB Z10, but I couldnt find how to install korean langauge on my Z10, but as I saw some info that BB Z10 support input Korean language also.. There are choice of many language but not Korean langauge... if anyone know how
-
File name of Document stored through OAAD
Hi Experts, We are using tcode - OAAD to store any document against employee. Following are the inputs provided to the system while storing the document. 1. Business Object - The value used in our case is "PREL" 2. Document type - The value used in o
-
Changing the next spool number
Hello, Can anyone tell me in what transaction I control the next spool number that will be created when a job is sent to a device in SAP R/3 ? Thanks, Mark
-
Accessing Discoverer Reports from Oracle Apps
Hi all, Requirement: Accessing Discoverer Reports from Oracle Apps Discoverer: 11g Oracle Apps: 12i When I am trying to access the Discoverer Reports from Oracle apps, again it is asking for Oracle Apps Login details. Can we have any other option tha
-
Hi, does anybody know how to add a scrollable text field to a slide? Or, at least, to imitate it? (In contrast to the text scrolling effects in iMovie I'd like to be able to stop and proceed scrolling by moude click.) Thanks for your suggestions. Dua