Change multiple column to rows using unpivot or pivot
is there any way I could use pivot or unpivot to get the result show in the graph? From the top table structure to the lower table structure. I could do activity hours and desc separately using unpivot but do not know how to join them together.
Looks like a pivot isn't the best bet, try this:
DECLARE @ActivityReport TABLE ([Employee_ID] [int] NULL, [Week] nvarchar(50) NULL, [Hours_Admin] [float] NULL, [Desc_Admin] [nvarchar](200) NULL, [Hours_HelpDesk] [float] NULL, [Desc_HelpDesk] [nvarchar](200) NULL, [Hours_Support] [float] NULL, [Desc_Support] [nvarchar](200) NULL)
insert into @ActivityReport VALUES (1, 'week1', 5, 'desc', 6, 'desc', 9, 'desc'), (1, 'week2', 5, 'desc1', 6, 'desc1', 9, 'desc1'), (2, 'week1', 5, 'desc', 6, 'desc', 9, 'desc'), (2, 'week2', 5, 'desc2', 6, 'desc2', 9, 'desc2')
SELECT employee_ID, week, hours_admin AS activityHours, 'admin_hours' AS activity_type
FROM @ActivityReport
UNION ALL
SELECT employee_ID, week, hours_helpdesk AS activityHours, 'helpdesk_hours' AS activity_type
FROM @ActivityReport
UNION ALL
SELECT employee_ID, week, hours_support AS activityHours, 'support_hours' AS activity_type
FROM @ActivityReport
ORDER BY Employee_ID, week
Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.
Similar Messages
-
Split multiple columns into rows using XML
Hi Forum,
I am trying to split 2 columns that each contain values separated by semicolon into single rows. The relation between the values of the two columns is that the order in the cells corresponds to each other.
The data looks like this:
pk Manufacturer partnumber
1 Man1; Man2;Man3 PN1;PN2;PN3
2 Man4; Man2;Man5 PN4;PN5;PN6
The result should be:
pk Manufacturer partnumber
1 Man1 PN1
1 Man2 PN2
1 Man3 PN3
2 Man4 PN4
2 Man2 PN5
2 Man5 PN6
I am not sure how to format the XML to get a useful Basis for XML.value or XML.query
Any ideas?
TIA
AlexHi,
Try like this ,
DECLARE @tmp TABLE (pk INT,Manufacturer NVARCHAR(50),partnumber NVARCHAR(50))
INSERT @tmp SELECT 1,'Man1; Man2;Man3','PN1;PN2;PN3'
INSERT @tmp SELECT 2,'Man4; Man2;Man5','PN4;PN5;PN6'
SELECT * FROM @tmp
SELECT tmp2.pk pk,Manufacturer,partnumber FROM (
SELECT ROW_NUMBER()OVER(ORDER BY tmp1.pk) RN,* FROM (
SELECT pk,
LTRIM(i.value('.','varchar(100)')) Manufacturer
FROM ( SELECT pk, Manufacturer,
CONVERT(XML,'<r><n>'
+ REPLACE(Manufacturer,';', '</n><n>') + '</n></r>') AS X
FROM @Tmp) Spt
CROSS APPLY Spt.X.nodes('//*[text()]') x(i)
) tmp1 ) tmp2
JOIN
(SELECT ROW_NUMBER()OVER(ORDER BY pk) RN,* FROM (
SELECT pk,
j.value('.','varchar(100)') partnumber
FROM ( SELECT pk, partnumber,
CONVERT(XML,'<r><n>'
+ REPLACE(partnumber,';', '</n><n>') + '</n></r>') AS Y
FROM @Tmp) Spt
CROSS APPLY Spt.Y.nodes('//*[text()]') y(j)) tmp2 ) tmp3 ON tmp3.RN = tmp2.RN
sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **. -
Mild challenge -pivoting *multiple* columns per row using only SQL
Hello All,
I'm in the process of learning the various pivoting techniques available
in SQL, and I am becoming more familiar with the decode,function,group-by
technique seen in many examples on these forums. However, I've got a case
where I need to pivot out 3 different columns for 3 rows of data where the
value of a different column is driving whether or not those columns are pivoted.
I know that last sentence was as clear as mud so I'll show you/provide the simple
scripts and data, and then I'll elaborate a little more beneath.
create table temp_timeline (
mkt_id varchar2(10),
event_id number(8),
event_type varchar2(3),
mod_due_date date,
cur_due_date date,
act_due_date date
insert into temp_timeline values('DSIM6',51,'S1','NOV-13-06','NOV-13-06',NULL);
insert into temp_timeline values('DSIM6',51,'S2','DEC-20-06','DEC-20-06',NULL);
insert into temp_timeline values('DSIM6',51,'S3','JAN-17-07','JAN-17-07',NULL);
insert into temp_timeline values('DSIM6',51,'S4','FEB-14-07','FEB-14-07',NULL);
commit;
select * from temp_timeline;
The "normal" output (formatted with period-separated fields) is:
DSIM6.51.S1.NOV-13-06.NOV-13-06.NULL
DSIM6.51.S2.DEC-20-06.DEC-20-06.NULL
DSIM6.51.S3.JAN-17-07.JAN-17-07.NULL
DSIM6.51.S4.FEB-14-07.FEB-14-07.NULL
The DESIRED 1-row output (formatted with period-separated fields) is:
DSIM6.51.NOV-13-06.NOV-13-06.NULL.DEC-20-06.DEC-20-06.NULL.JAN-17-07.JAN-17-07.NULL.FEB-14-07.FEB-14-07.NULL
So, the first 2 columns in the table have the same data, and the third column
makes the row unique (they could all have the same/similar dates).
If this table only consisted of the first 3 columns then many of the examples seen
on this forum would work well (grouping by the first 2 rows and pivoting out
the "event_type" columns containing (S1,S2,S3,S4) etc.
But, in my case, I need to discard the event_type column and pivot out the
3 columns of date data onto the first row (for each different event_type).
So the 3 Dates associated with the "S2" column would go to the first row, and the
3 dates associated with the "S3" column would also go to the first row (and so on).
The 3 dates need to be 3 distinct columns when they are
pivoted out (not concatenated to each other and pivoted as one column).
Given this, I will need to pivot out a total of 12 different columns for each distinct
(mkt_id, event_id) pair.
For the time being I have accomplished this with a union, but am trying to expand
my abilities with other sql methods. I've seen some very elegant solutions on this
forum so will be interested to see what others can come up with for this solution.
Thanks in advance for any comments you may provide.Just DECODE based on the event type, which will generate your 12 columns.
SELECT mkt_id, event_id,
MAX(DECODE(event_type, 'S1', mod_due_date, NULL)) s1_mod_due,
MAX(DECODE(event_type, 'S1', cur_due_date, NULL)) s1_cur_due,
MAX(DECODE(event_type, 'S1', act_due_date, NULL)) s1_act_due,
MAX(DECODE(event_type, 'S2', mod_due_date, NULL)) s2_mod_due,
MAX(DECODE(event_type, 'S2', cur_due_date, NULL)) s2_cur_due,
MAX(DECODE(event_type, 'S2', act_due_date, NULL)) s2_act_due,
MAX(DECODE(event_type, 'S3', mod_due_date, NULL)) s3_mod_due,
MAX(DECODE(event_type, 'S3', cur_due_date, NULL)) s3_cur_due,
MAX(DECODE(event_type, 'S3', act_due_date, NULL)) s3_act_due,
MAX(DECODE(event_type, 'S4', mod_due_date, NULL)) s4_mod_due,
MAX(DECODE(event_type, 'S4', cur_due_date, NULL)) s4_cur_due,
MAX(DECODE(event_type, 'S4', act_due_date, NULL)) s4_act_due
FROM temp_timeline
GROUP BY mkt_id, event_idTested, because you supplied create table and insert statements, thank you.
John -
Multiple columns and rows in MessageService
I am attempting to create a message (via MessageService) which has multiple lines of data, and each line has multiple data columns.
Background: My program reads data from a web store, and creates Sales Orders in SBO. A single run might process multiple orders. When all orders have been entered, the program should send a (single) message to a list of recipients. The message will have one line of data for each sales order produced. Each line will contain two fields: the linked SBO sales order number, and the unlinked web order number.
When the message is initially created, I'm defining the multiple columns and initializing the data lines:
pMessageDataColumns = oMessage.MessageDataColumns
pMessageDataColumn = pMessageDataColumns.Add()
pMessageDataColumn.ColumnName = "SalesOrder"
pMessageDataColumn.Link = BoYesNoEnum.tYES
pMessageDataColumn = pMessageDataColumns.Add()
pMessageDataColumn.ColumnName = "WebOrder"
pMessageDataColumn.Link = BoYesNoEnum.tNO
oLines = pMessageDataColumn.MessageDataLines()
Later, as each Sales Order is processed, I'm attempting to inject the two data values into the message data:
oLine = oLines.Add()
oLine.Value = Str(pOrd.DocNum)
oLine.Object = 17
oLine.ObjectKey = Str(pOrd.DocEntry)
oLine = oLines.Add()
oLine.Value = pOrd.WebOrder
The above code would be invoked for each Sales Order processed. However, it generates an "Internal error (-5002) occurred" when the message is ultimately sent.
The SDK documentation states:
The MessageDataLine is a child data structure related to the MessageDataColumn. It contains the value of a specified cell in the Data table, which is defined by its column number (vtIndex of Item of MessageDataColumns) and row number (vtIndex of Item of MessageDataLines).
I guess I don't understand the relationship between adding a "line" in my data display versus adding data into a "column". It appears that the "oLines.Add()" is used to bump across the columns of the data. If so, how do I advance to the next entire row of data in the message?
Thanks, DaveClass Item
Public ItemCode As String
Public Dscription As String
End Class
Dim ItemCodes as new list( of item)
Dim one as new item
one.ItemCode = "ItemCode"
one. Dscription ="Name of Item"
itemcodes.add (one)
Try
Dim oCmpSvc As SAPbobsCOM.CompanyService = _ocmp.GetCompanyService()
Dim oMsgSvc As SAPbobsCOM.MessagesService = oCmpSvc.GetBusinessService(ServiceTypes.MessagesService)
Dim oMsg As SAPbobsCOM.Message = oMsgSvc.GetDataInterface(MessagesServiceDataInterfaces.msdiMessage)
oMsg.Subject = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
oMsg.Text = Msg
Dim oMsgDataColumn As SAPbobsCOM.MessageDataColumn
If ItemCodes.Count > 0 Then
oMsgDataColumn = oMsg.MessageDataColumns.Add()
oMsgDataColumn.ColumnName = "Product / Item Code"
oMsgDataColumn.Link = BoYesNoEnum.tYES
For Each oneitem As Item In ItemCodes
Dim oMsgDataLine As SAPbobsCOM.MessageDataLine = oMsgDataColumn.MessageDataLines.Add()
oMsgDataLine.Object = "4"
oMsgDataLine.ObjectKey = oneitem.ItemCode
oMsgDataLine.Value = oneitem.Dscription
Next
oMsgDataColumn = oMsg.MessageDataColumns.Add()
oMsgDataColumn.ColumnName = "Description"
oMsgDataColumn.Link = BoYesNoEnum.tNO
For Each oneitem As Item In ItemCodes
Dim oMsgDataLine As SAPbobsCOM.MessageDataLine = oMsgDataColumn.MessageDataLines.Add()
oMsgDataLine.Value = oneitem.Dscription
Next
End If
Dim oMsgRecipient As SAPbobsCOM.Recipient = oMsg.RecipientCollection.Add()
oMsgRecipient.UserCode = "manager"
oMsgRecipient.SendInternal = BoYesNoEnum.tYES
oMsgRecipient.SendEmail = BoYesNoEnum.tNO
oMsgSvc.SendMessage(oMsg)
MsgBox("SAP B1 internal Message sent...")
Catch ex As Exception
MsgBox("Unable to send SAP B1 internal message. Error:" + ex.Message)
End Try
End Sub -
Hello everyone,
I am developing an application (ALV OO) to select more than 1 column by row ( one ). This is an a holiday application so the idea is:
-One column will be the day, and the row will be the user.
So I am trying to select more than one day by user (that would be the row).
I am using the method set_table_for_first_display but when it shows the alv, doesn't let me to select more than one column with a click of the mouse.
Does anybody know if I can do this (select more than one column, by row) in somehow?
Please let me know if you need more clarification about this.
Thanks in advance
DiegoHi Diego,
it's all in the documentation.
set different selection modes through the value of the field u201CSEL_MODEu201D in the layout structure.
SPACE
same as 'B'
see 'B'
Default setting
'A'
Column and row selection
Multiple columns
Multiple rows
The user selects the rows through pushbuttons at the left border of the grid control.
'B'
Simple selection, list box
Multiple columns
Multiple rows
'C'
Multiple selection, list box
Multiple columns
Multiple rows
'D'
Cell selection
Multiple columns
Multiple rows
Any cells
The user selects the rows through pushbuttons at the left border of the grid control
Beyond setting this option, you can set u201CNO_ROWMARKu201D option to hide the mark column which is normally visible when the selection mode allows multiple row selection.
One point to notice here is that if you set your ALV Grid as to be editable, it may override your selection mode regardless of your layout settings.
This is from SDN Community Contribution "An Easy Reference for ALV Grid Control" By: Serdar ŞİMŞEKLER
Sorry, no link,. it's on my disk.
Regards,
Clemens -
Transporting columns into rows using SSIS
Hi everyone,
Just need some help.
I wanna transpose a data table in SSIS.
The table is originally
CUSTREFNO
Citizen
FORENAME
Citizen
SURNAME
Citizen
DATE-OF-BIRTH
Citizen
TEL_NO
Citizen
GUARDIANNAME
Citizen
ADDRESS1
Citizen
ADDRESS2
Citizen
ADDRESS3
Citizen
ADDRESS4
Citizen
POSTTOWN
Citizen
POSTCODE
Citizen
OPERATOR
Junk
BOARDINGPOINT
Junk
DESTINATION
Junk
SERVICE_NO
Junk
EMAIL
Citizen
And i need the table in the following format
CUSTREFNO
FORENAME
SURNAME
DATE-OF-BIRTH
TEL_NO
GUARDIANNAME
ADDRESS1
ADDRESS2
ADDRESS3
ADDRESS4
POSTTOWN
POSTCODE
OPERATOR
BOARDINGPOINT
DESTINATION
SERVICE_NO
EMAIL
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Citizen
Junk
Junk
Junk
Junk
Citizen
Any help, would be very much appreciated, thanksUmar, please see these resources.
http://blogs.msdn.com/b/philoj/archive/2007/11/10/transposing-rows-and-columns-in-sql-server-integration-services.aspx
http://www.rad.pasfu.com/index.php?/archives/14-PIVOT-Transformation-SSIS-Complete-Tutorial.html
http://dinesql.blogspot.in/2011/08/pivot-and-unpivot-integration-services.html
http://sqlage.blogspot.in/2013/12/ssis-how-to-use-unpivot-in-ssis.html
http://www.bimonkey.com/2009/06/the-pivot-transformation/
http://www.sql-server-performance.com/2007/ssis-pivot-unpivot/
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
Changing the column position & width using Screen Variant..
Hi Experts,
Iam trying to change the column position and width for the standard transaction (eg. FB60 or VA02) using the transaction code SHD0 (Transaction and Screen Variant).
Iam able to create and save the transaction and screen variant and i could see the check box options for table control like
a. Auto Column Position
b. Auto Column Width
I tried checking and unchecking both the check boxes but iam unable to modify / maintain the column position and width.
Please guide me in changing the column position and width.
Thanks in Advance.Hi Mudit,
Kindly go through this link below:
http://help.sap.com/saphelp_nw04/Helpdata/EN/9f/dbac0b35c111d1829f0000e829fbfe/content.htm
Hope it helps you
Regrds
Mansi -
How to convert columns into rows using transpose function
Hi
anybody tell me how to convert columns values into rows using transpose function.Since BluShadow went to all the trouble to put it together, someone should use it.
See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
John -
Multiple columns and rows update using select staement
i am trying to update the 2 colums of a table based on the cursor result set with key values are matching.
DECLARE
CURSOR update_master
IS
SELECT B.cust_num,c.cust_num,
B.cust_name,B.cust_bal
FROM
Table_one B
JOIN
Table_two C
ON B.cust_num= C.cust_num;
BEGIN
FOR master_rec IN update_master
LOOP
UPDATE Table_three
SET col1 = master_rec.cust_name,
Col2 = master_rec.cust_bal,
Where WHERE Cust_num = master.cust_num;
END LOOP;
COMMIT;
END;
The 3 tables are having around 50000 records individually............
It is taking too much of time to execute......more than 6 minutes......
how can we optimize it?? can we write this update statement directly? instead of writing it in procedure?Here's a general approach:
update some_table s
set (s.col1, s.col2) = (select x.col1, x.col2
from other_table x
where x.key_value = s.key_value
where exists (select 1
from other_table x
where x.key_value = s.key_value
; -
Is it possible to group multiple columns individually without using union?
Hi, if I have a table with a numebr of columns I want to group eg gender, nationality, age and I want to produce a summary such like:
Group Count
Male 10
Female 23
British 19
Irish 14
18 10
etc.
Or even better:
Group Count
Gender-Male 10
Gender-Female 23
Nationaility-British 19
Nationality-Irish 14
Age-18 10
Is this possible without using loads of unions? I just want to do this in the best, most efficient way as the table involved has >100 million rows.
Many thanks
Jen :)May be this
--Test data
with t
as
select 'M' gender, 'INDIAN' nationality, 25 age from dual union all
select 'M' gender, 'INDIAN' nationality, 25 age from dual union all
select 'M' gender, 'INDIAN' nationality, 30 age from dual union all
select 'M' gender, 'IRISH' nationality, 30 age from dual union all
select 'M' gender, 'IRISH' nationality, 40 age from dual union all
select 'F' gender, 'IRISH' nationality, 40 age from dual union all
select 'F' gender, 'BRITISH' nationality, 50 age from dual union all
select 'F' gender, 'BRITISH' nationality, 50 age from dual union all
select 'F' gender, 'BRITISH' nationality, 45 age from dual union all
select 'F' gender, 'BRITISH' nationality, 45 age from dual
--Test Data Ends
-- Main Query
select decode(no, 1, 'Gender-', 2, 'Nationality-', 3, 'Age-') || decode(no, 1, gender, 2, nationality, 3, to_char(age)) val,
count(*) cnt
from t
cross join (select level no from dual connect by level <= 3)
group by no, decode(no, 1, gender, 2, nationality, 3, to_char(age))
order by no;
VAL CNT
Gender-F 5
Gender-M 5
Nationality-BRITISH 4
Nationality-INDIAN 3
Nationality-IRISH 3
Age-25 2
Age-30 2
Age-40 2
Age-45 2
Age-50 2
10 rows selected -
Inserting multiple columns into database using dbtool set
I have a labVIEW program that is currenly simulating voltage and a current signal using the DAQ Assistant. I'm using the database connectivity toolset. I am currently able to insert one signal into the database converted to a float(I can insert both into the same column as bianary but it needs to be stored as a usable format and in seperate columns.)
The problem I am having is at the DB Tools Insert Data block. I have the connection, dbTable, error code, and create table boolean being passed into it. Where I am a little lost is how to set the columns I want to store the multiple signals into.
If someone could break that part down for me that would be great. In short, I want to store voltage(channel0) and current(channel1) from the DAQ Assistant into their own respective columns in the db.
Message Edited by DonPoulson on 07-10-2007 11:04 AMDon,
This particular forum is specific to TestStand, not LabVIEW or Multifunction DAQ. You may have a better chance at responses by posting to either of those forums rather than here.
Brandon Vasquez | Software Engineer | Integration Services | National Instruments -
How to insert parameter value into multiple columns and rows
Hi All,
I have one procedure insert_tab and I am passing
100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
Table:
Col1 Col2 Col3
100 101 102
103 104 105
106 107 108
Awaiting for your reply..That's not more clear for me...
Anyway, if you really want a procedure for that, try :
SQL> create table tblstr (col1 number,col2 number,col3 number);
Table created.
SQL>
SQL> create or replace procedure insert_fct (p_string IN varchar2)
2 as
3 v_string varchar2(4000):=p_string||':';
4 v_substring varchar2(4000);
5
6 begin
7 while instr(v_string,':') > 0 loop
8 v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
9 insert into tblstr(col1,col2,col3)
10 values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
11 substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
12 substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
13 v_string:=substr(v_string,instr(v_string,':')+1);
14 end loop;
15 end;
16 /
Procedure created.
SQL>
SQL> show err
No errors.
SQL>
SQL> select * from tblstr;
no rows selected
SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
SQL> exec insert_fct('109~~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~110~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~~111')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
109
110
111
6 rows selected.
SQL> Nicolas. -
SQL Help with change multiple columns into a single column
I am wanting to create either a new View or a new Table based on the following original table:
Original Table:
Fiscal Year
Account
Budget_Amt_January
Budget_Amt_February
Budget_Amt_March
Budget_Amt_April
<etc. for each of the 12 months)
I want the new View or Table to instead be:
New:
Fiscal_Year
Month
Account
Budget_Amount
I can't simply drop the original table, it will have to always exist since it is part of the Finance package, but for ease of reporting against I am wanting to create this new View.
Any ideas on how to go about this?
Thanks!I had to do something very similar just this week - in my case a record read from a csv into a table, then needs loading into a destination table, and the rows are columns in the csv. I went for INSERT ALL as I also had some conditions.
INSERT ALL
WHEN low1 != -998 OR high1 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 1, low1, high1 )
WHEN low2 != -998 OR high2 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 2, low2, high2 )
WHEN low5 != -998 OR high5 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 5, low5, high5 )
WHEN low6 != -998 OR high6 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 6, low6, high6 )
WHEN low7 != -998 OR high7 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 7, low7, high7 )
WHEN low8 != -998 OR high8 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 8, low8, high8 )
WHEN low9 != -998 OR high9 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 9, low9, high9 )
WHEN low10 != -998 OR high10 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 10, low10, high10 )
WHEN low11 != -998 OR high11 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 11, low11, high11 )
WHEN low12 != -998 OR high12 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 12, low12, high12 )
WHEN low13 != -998 OR high13 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 13, low13, high13 )
SELECT * FROM bulk_search_load bst, partial_details_temp pdt
WHERE id = case_number -- only retrieves details for those records that are found in bulk_search_load
AND filename like 'NETH\_%' escape '\'
AND processed = 'N'; -
Problem in showing multiple columns and rows in horizontal wrap as like as
I am trying to implement the ListView in my application as like as in windows.
But i am able to show single row by this code snippet.
What should i do to show the multiple row ,multiple coloumns in JList.
import javax.swing.*;
import java.awt.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class JListExample extends JFrame
private class Value
Value(String value, Icon image)
this.value = value;
this.image = image;
String value;
Icon image;
private Icon getIcon(String name)
return new ImageIcon(name);
public JListExample()
super("Simple JList Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Value[] VALUES =
new Value("the road", getIcon("10.jpg")),
new Value("trees", getIcon("11.jpg")),
new Value("stooges", getIcon("12.jpg")),
new Value("bauld tires", getIcon("13.jpg")),
new Value("bvot tires", getIcon("14.jpg")),
new Value("volt tires", getIcon("15.jpg")),
new Value("send tires", getIcon("17.jpg")),
JList list = new JList(VALUES);
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(1);
list.setCellRenderer(new SimpleCellRenderer());
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (evt.getValueIsAdjusting())
return;
System.out.println("Selected from " + evt.getFirstIndex()
+ " to " + evt.getLastIndex());
JScrollPane ListViewer = new JScrollPane(list);
getContentPane().add(ListViewer);
setBounds(0,0,600,600);
//pack();
public static void main(String[] args)
try
new JListExample().setVisible(true);
catch (Exception e)
e.printStackTrace(System.out);
class SimpleCellRenderer extends JLabel implements ListCellRenderer
public SimpleCellRenderer()
setOpaque(true);
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
Value val = (Value)value;
setText(val.value);
setIcon(val.image);
//setBackground(isSelected ? Color.red : (index & 1) ==0 ? Color.cyan : Color.green);
//setForeground(isSelected ? Color.white : Color.black);
return this;
}I know this is an old topic, but I found the solution and thought I'd share it! By default, a JList only has 1 visible row. To allow the number of rows to expand dynamically, throw this in.
this.imageList.setVisibleRowCount(-1);My code looks like this. It centers each image and centers the text under the image and wraps images horizontally.
ListCellRenderer renderer = new ImageListCellRenderer();
this.imageList.setCellRenderer(renderer);
DefaultListModel listModel = new DefaultListModel();
this.imageList.setVisibleRowCount(-1);
this.imageList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
this.imageList.setModel(listModel);and the renderer
public class ImageListCellRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int
index, boolean isSelected, boolean hasFocus) {
JLabel label = (JLabel)super.getListCellRendererComponent(list, value,
index, isSelected, hasFocus);
if (value instanceof File) {
File imageFile = (File)value;
String path = imageFile.getAbsolutePath();
Image image = Toolkit.getDefaultToolkit().getImage(path);
image = image.getScaledInstance(100, 100, Image.SCALE_DEFAULT);
ImageIcon imageIcon = new ImageIcon(image);
label.setIcon(imageIcon);
label.setText(path.substring(path.lastIndexOf(File.separatorChar) + 1));
label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setHorizontalTextPosition(SwingConstants.CENTER);
else {
label.setIcon(null);
return label;
}I need to work on this to improve performance, but it works! -
Convert Column to rows using sql
My client relies on a legacy system which currently outputs data in the following format:
001
100test1
110addr1
115addr2
120city
125state
999drr
001
100test1
110addr1
115addr2
120city
125state
130XXX
135YYY
140ZZZ
999drr
001
100test1
110addr1
115addr2
120city
125state
145AAA
150BBB
155CCC
999drr
I want to transform the above data into the format, as shown below:
Name | ADDR1 | ADDR2 | CITY | STATE | ColX | ColY | ColZ | ColA | ColB | ColC | .... | LastCol
100test1 | 110addr1 | 115addr2 | 120city | 125state | null | null | null | null | null | null | ... | null
100test1 | 110addr1 | 115addr2 | 120city | 125state | 130XXX | 135YYY | 140ZZZ | null | null | null | ... | null
100test1 | 110addr1 | 115addr2 | 120city | 125state | null | null | null | 145AAA| 150BBB | 155CCC | ... |null |
When I tried , it only works when the number of rows between '001' and '999' is fixed. But, in my case, the data I get is never fixed and there can be any number of rows in betweeen '001' and '999' and The rows with null values do not show up at all in the flatfile (as shown above in the third block).
Can anyone help about how to achieve this kind of data transformation ? What sequence of steps or scripts do I have to run to get this?
Any help is appreciated.
Thanks ahead
premaI have considered that 7 consecutive rows forms one record. Change the 7 in the query according to your actual data.
SQL> with t
2 as
3 (
4 select '001' detail from dual
5 union all
6 select '100test1' from dual
7 union all
8 select '110addr1' from dual
9 union all
10 select '115addr2' from dual
11 union all
12 select '120city' from dual
13 union all
14 select '125state' from dual
15 union all
16 select '999drr' from dual
17 union all
18 select '002' from dual
19 union all
20 select '200test2' from dual
21 union all
22 select '210addr1' from dual
23 union all
24 select '215addr2' from dual
25 union all
26 select '220city' from dual
27 union all
28 select '225state' from dual
29 union all
30 select '999drr' from dual
31 union all
32 select '003' from dual
33 union all
34 select '300test1' from dual
35 union all
36 select '310addr1' from dual
37 union all
38 select '315addr2' from dual
39 union all
40 select '320city' from dual
41 union all
42 select '325state' from dual
43 union all
44 select '999drr' from dual
45 )
46 select ltrim(max(sys_connect_by_path(detail,'|')),'|')
47 from
48 (
49 select row_num,
50 trunc(abs(decode(row_num-rownum,0,1,row_num-rownum))/7)+1 row_num1,
51 detail
52 from
53 (
54 select decode(mod(rownum,7),0,7,mod(rownum,7)) row_num,detail
55 from t
56 )
57 )
58 start with row_num=1
59 connect by row_num-1=prior row_num
60 and row_num1= PRIOR row_num1
61 group by row_num1
62 /
LTRIM(MAX(SYS_CONNECT_BY_PATH(DETAIL,'|')),'|')
001|100test1|110addr1|115addr2|120city|125state|999drr
002|200test2|210addr1|215addr2|220city|225state|999drr
003|300test1|310addr1|315addr2|320city|325state|999drrRegards,
Mohana
Maybe you are looking for
-
I would like to improve the quality of my iTunes library, most of which were ripped at the old 'higher quality' setting and not lossless. I would consider subscribing to the iTunes Match programme if I would later be able to download my music back on
-
Error: Insufficient permission on the folder in which the format is to be s
Hi Experts, I have two users A and B. Now A is sharing a OLAP worksheet with B and getting following error. oracle.dss.d4o.common.D4OException: D4O-1209 Insufficient permission on the folder in which the format is to be saved. oracle.dss.bicontext.BI
-
Hi, I need a little help. We want to upgrade from 10.7 (Char) to 11i. We have 150 peak user (total around 200). How many servers do we need? Is it sufficient to have 1 NT for database, 1 NT for application and web listener and 1 Unix for concurrent p
-
Pre Populate AD UserPrincipalName with multiple IT Resources and 1 form - 11g r2
I have an ICF AD connector with 3 IT resources, each one having a different domain (i.e. example.us.com, users.eu.com....). I only have 1 resource form though. When I prepopulate the UPN field, I have to do userlogin@domainame. When I go to map the v
-
Save a user's artwork to a server
I want to make a Flash file where users can type in text, draw (or maybe choose from a selection of) images and then save the changes to either (or both) the server and their hard disk. Any help or pointers would be very much appreciated.