Split a Column to Three Columns
Hello Y'all Gurus,
I have a column and I need to split this column to three columns. The following are samples of data to be split:
Sample #1:
From
Column: 2.5 (3 - 47) or
2.5 (3-47) or
2.5(3 -47) or
2.5(3-41/47)
To
Column #1: 2.5
Column #2: 3
Column #3: 47
Sample #2:
From
Column: 4X6(2-72)
To
Column #1: 4
Column #2: 2
Column #3: 72Any and all the help would be greatly appreciated.
Thanks in advance.
Hi,
Try this. If there are any cases this may fail let me know. Not unit tested.
SQL> WITH T
2 AS (SELECT '2.5 (3 - 47)' TXT FROM DUAL
3 UNION ALL
4 SELECT '2.5 (3-47)' FROM DUAL
5 UNION ALL
6 SELECT '2.5(3 -47)' FROM DUAL
7 UNION ALL
8 SELECT '2.5(3-41/47)' FROM DUAL
9 UNION ALL
10 SELECT '4X6(2-72)' FROM DUAL)
11 SELECT REGEXP_SUBSTR (TXT, '^(\.[0-9]+|[0-9]+(\.[0-9]*)?)') COL1
12 ,LTRIM (REGEXP_SUBSTR (TXT, '\((\.[0-9]+|[0-9]+(\.[0-9]*)?)'), '(') COL2
13 ,RTRIM (REGEXP_SUBSTR (TXT, '(\.[0-9]+|[0-9]+(\.[0-9]*)?)\)'), ')') COL3
14 FROM T;
COL1 COL2 COL3
2.5 3 47
2.5 3 47
2.5 3 47
2.5 3 47
4 2 72
SQL> G.
Similar Messages
-
Webi report display splits a column
Hi
fairly new to Webi so I hope this doesn't sound too basic. I have a Webi report that is 30 odd columns wide (this is currently BOXI R2 on Windows 2003); it's displayed in Landscape mode and splits several columns down the middle. How can you define where the vertical page breaks should be and/or which columns should not be split?
Cheers
Mark GillisThanks for getting back. That's not quite the problem: it's a 'standard' Webi report (not a crosstab) and has over 40 columns. Even in landscape mode, that displays over 5 pages. The problem is vertical splits: I can fit columns 1 to 7 on page 1 and then column 8 is half on the first page and half on the second (this is displaying in Page mode in Infoview: I can display in Draft mode, of course, to get a full span display of the report).
What I'm trying to do is define the report so that when a user displays in Page mode columns do not get split. It may be that Draft mode is the only answer but I was hoping a setting would exist to say "don't split columns over pages". -
Split a column based on even and odd rows
Table1
Table2
Col1
Odd
Even
A
A
B
B
C
D
C
E
F
D
G
H
E
I
NULL
F
G
H
I
I am using MS SQL v2005
I want to split a column into two columns : -
one column must have all the odd rows data while the other column must have even rows data
in other words I want the data in Table1 to be displayed as data in Table2.
Col, Odd and Even are column namesIn SQL 2005 wont approach like what I suggested do only a single scan of the table?
A major problem with your solution is that you assume that 1) the values are contiguous 2) they are numeric. Try the below:
CREATE TABLE #t (id INT NOT NULL IDENTITY(1,1), Col1 CHAR(1))
INSERT INTO #t VALUES ('A'),('B'), ('C'),('D'), ('E'),('F'), ('G'), ('H'), ('I')
go
SELECT MAX(CASE WHEN Col1 % 2 > 0 THEN Col1 END),
MAX(CASE WHEN Col1 % 2 = 0 THEN Col1 END)
FROM
SELECT Col1,ROW_NUMBER() OVER (PARTITION BY (Col1 % 2) ORDER BY Col1) AS Rn
FROM #t
)t
GROUP BY Rn
go
; WITH numbering AS (
SELECT Col1, row_number() OVER (ORDER BY Col1) AS rowno
FROM #t
), leading AS (
SELECT Col1 AS odd, LEAD(Col1) OVER(ORDER BY rowno) AS even, rowno
FROM numbering
SELECT odd, even
FROM leading
WHERE rowno % 2 = 1
go
DROP TABLE #t
Erland Sommarskog, SQL Server MVP, [email protected] -
How to split a column in adobe livecycle design?
How does one split a column in adobe livecycle design. I have found that one can split a column after you have merged it. But I want to split two columns into four in the middle of a table. This can be done in Word. Is there a way even if one has to split each row? Does any one know? Like in the table below I would like to make Header 2 & Header 3, Rows 2 and 3 into 2 rows 4 columns.
Header 1
Header 2
Header 3
Header 4
Thanks
SheilaIf you want to have 1 column to be split in 4 columns, you can insert a table with 4 columns inside a column cell.. If you mean to add rows and you want to keep those 4 columns, you should add instances of the row where you inserted the table with 4 columns...
Hope this helps!
Mag -
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 **. -
Splitting one column into different columns.
Hello Experts,
How do i split datetime column into different columns while doing a Select statement.
Ex:
The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is "DateTime". And i want it in SELECT statement like;
SELECT
YEAR(DATETIME) YEAR,
MONTH(DATETIME) MONTH,
DATENAME(DATETIME) MONTHNAME,
DATEPART(DATETIME) WEEKNUM,
DAY(DATETIME) DATE,
DATEPART(DATETIME) HOUR
FROM TABLE_NAME;
The output should look like this;
--YEAR| MONTH | MONTHNAME| WEEKNUM | DATE | HOUR
--2014| 5 | May | 25 | 08 |08
Any suggestions please.
Thanks!
RahmanI made a very quick research and I see in this blog post
http://www.jamesserra.com/archive/2011/08/microsoft-sql-server-parallel-data-warehouse-pdw-explained/
that It also uses its own query engine and not all features of SQL
Server are supported. So, you might not be able to use all your DBA tricks. And you wouldn’t want to build a solution against SQL Server and then just hope to upsize it to Parallel Data Warehouse Edition.
So, it is quite possible that this function doesn't exist in PDW version of SQL
Server. In this case you may want to implement case based month name or do it in the client application.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Splitting of column into furthur subcolumn's into an ALV list
Hi All,
I've to display the data in a alv grid in Such format.
category
name
age
|--|-|
sc
st
As far as i know there is no way available to split the column headinng furthur into subheadings.
But any how if it is possible please tell me.
Note : The above displayed list is just an eaxmple there may be dynamically furthur subdivision of it's heading.
--AmitAmit,
Its not possible to merge neither the headings nor the columns as such.
Regards,
Ravi -
Splitting one column into 4 columns
Hi,
I want to split one column into 4 columns as shown below.
parameters
PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
PanelPanel=MP12100173&YearYear=2013&Source=1&UserID=aac6440
it should be display as
panel yearyear source userid
MP01110201 2013 1 aad2779
MP12100173 2013 1 aac6440
there will be thousands of rows in the column. Can anybody help how to split it as shown.The length may very from row to row
Thanks for your help.........
BALUSUSRIHARSHAIt is working...thank u very much... I found one more issue here
PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
PanelPanel=MP11100070&Source=1&PNR=2&YearYear=2014&UserID=ddc1535
PanelPanel=MP11101276&Source=1&YearYear=2014&PNR=2&UserID=ddc1565
I found 3 kinds of formats in the same column... I didn't observe the data carefully while posting the
question..sorry about that. In this case if we need to show as
panel yearyear source
userid
MP01110201 2013 1 aad2779
MP11100070 2014 1 ddc1535
MP11101276 2014
1 ddc1565
is it possible to filter like this? Should we use any case statement in query while we have diff formats
like this?
BALUSUSRIHARSHA -
MRP, need to split total order in three week
Hi SAP GURU,
i need to split total order in three weeks. how i can make setting so that after MRP execution system will create proposals like 1st week302nd week 303rd week 40
Thanks,
SAP PQDear
Goto MD61-Enter Material -Goto User Parameters -Select Weekly (W) -Enter Weekly bucket qty in case u have PIR as your demand
In case if you have Sales Order oriented qty then you can use Scheduling agreement kind of forecasting in VA31 instea of MD61 or Yo can try Period Lot Size WB in Material master and logging Sales Order qty .
Check both cases in sandbox and look at MD04 result
regards
JH -
I split my clip in three ways, then deleted the middle clip
I have a question. I split my clip in three ways, then deleted the middle clip, what I do to join these three clips again ? I need some help. Is It only work with the Precision Editor? because i think it s so difficult!
Not sure I understand.
What do you mean by
when I cut back on the corner of a clip that connects to another,
If you do what I suggested above you should be able to bring back the original clip to the project from the event without affecting the other clips in the project ( ie without damaging the rest of the other cuts?)
You can drag the original clip (or any clip) to any position in the ' Time-line"
I assume from your post that you are using iMovie 11??? -
To split a column into multiple columns
Hi,
I have column and i want to split it into three columns as shown below given inputs and required outputs. I have written this query to get P_1, and p_2 but dont know how to get p_3.
SELECT ADDRESS,SUBSTR(ADDRESS,1, INSTR(ADDRESS,' ')-1) P_1
,SUBSTR(ADDRESS, instr(address,' ',-1)+1) P_2
FROM TT
Input:
ADDRESS
1 AVENUE OF THE AMERICAS
2 NORTH CAROLINE STREET EAST
236 TURPENTINE ROAD COOPER CREEK
REQUIRED OUTPUT
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
Thanks in advanceIf you're on 10g or 11g you can do something like this ...
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 4 21:18:07 2008
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
column p_1 format a3
column p_2 format a10
column p_3 format a30
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\1' ) as p_1 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\3' ) as p_2 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
3 rows selected.
-- or try this shorter version --
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
regexp_replace( address, '^([^ ]+).*', '\1' ) as p_1 ,
regexp_replace( address, '.*?([^ ]+)$', '\1' ) as p_2 ,
regexp_replace( address, '^([^ ]+) (.+?) ([^ ]+)$', '\2' ) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER
3 rows selected.See SQL Snippets: SQL Features Tutorials - Regular Expressions if you're unfamiliar with regular expressions.
If you can't / don't want to use regular expressions then you'll need to settle for a more boring approach like this one.
with data as
select '1 AVENUE OF THE AMERICAS' as ADDRESS from dual union all
select '2 NORTH CAROLINE STREET EAST' as ADDRESS from dual union all
select '236 TURPENTINE ROAD COOPER CREEK' as ADDRESS from dual
select
substr( address, 1, instr( address, ' ' ) - 1 ) as p_1 ,
substr( address, instr( address, ' ', - 1 ) + 1 ) as p_2 ,
substr
( address,
instr( address, ' ', + 1 ) + 1,
instr( address, ' ', - 1 ) - instr( address, ' ' ) - 1
) as p_3
from
data
P_1 P_2 P_3
1 AMERICAS AVENUE OF THE
2 EAST NORTH CAROLINE STREET
236 CREEK TURPENTINE ROAD COOPER--
Joe Fuda
SQL Snippets -
Splitting Single Column into 3 columns.
I have a column data like this
85052/123755 LAURITSEN/H HENRIK S MR
87432/119975 MORTENSEN/P PIA BUBANDT MS
73784/127530 PEDERSEN/M MORTEN H MR
88579/128347 JENSEN/M MORTEN MR
./AIRTECH STEFANSEN/P PER MR
10024/AIRTECH HOFFMANN/M MICHAEL KJUL MR
75922/128415 MOELLER/F FRANK MR
17639/128440 THOMSEN/P PETER MR
53198/127655 THYGESEN/E EBBE MR
85960/128473 ORAEINAMZADI/M MAZYAR MR
52663/128270 MAINZ/J JAN MR
17639/128440 THOMSEN/P PETER MR
27510/. HANSEN/N NILS HARLADSTED
43885/126300 LARSEN/J JOHNNI S MR
87580/125410 STEFANSEN/R RASMUS MR
63215/128445 NIELSSON/J JESPER MR
80594/123334 OLSEN/H HENRIK W MR
I need to split this into three columns
85052/123755 LAURITSEN/H HENRIK S MR
should be split as
Column1: 85052
Column2: 123755
Column3: LAURITSEN/H HENRIK S MR
but in some cases it may also be like this
./AIRTECH STEFANSEN/P PER MR
this should be split into
Column1: null
Column2: null
Column3: AIRTECH STEFANSEN/P PER MR
one more scenario is like this
27510/. HANSEN/N NILS HARLADSTED
Column1: 27510
Column2: null
Column3: HANSEN/N NILS HARLADSTED
Pls Help
Thanks
Vinoth.Based on the sample data you provided,
SQL> WITH T
2 AS (SELECT '85052/123755 LAURITSEN/H HENRIK S MR' str FROM DUAL
3 UNION ALL
4 SELECT './AIRTECH STEFANSEN/P PER MR' str FROM DUAL
5 UNION ALL
6 SELECT '10024/AIRTECH HOFFMANN/M MICHAEL KJUL MR' str FROM DUAL
7 UNION ALL
8 SELECT '27510/. HANSEN/N NILS HARLADSTED' str FROM DUAL)
9 SELECT REGEXP_REPLACE (REGEXP_SUBSTR (str, '[^/]+', 1, 1), '[^[:digit:]]') col1
10 ,REGEXP_REPLACE (REGEXP_SUBSTR (str, '[^/]+', 1, 2), '[^[:digit:]]') col2
11 ,REGEXP_SUBSTR (str, '[[:alpha:]].*', 1, 1) col3
12 FROM T;
COL1 COL2 COL3
85052 123755 LAURITSEN/H HENRIK S MR
AIRTECH STEFANSEN/P PER MR
10024 AIRTECH HOFFMANN/M MICHAEL KJUL
27510 HANSEN/N NILS HARLADSTED
SQL> G. -
Splitting a column data into 4 different columns
HI ALl,
I have a column that bring the data friom the database like this :
1.1.01 10.1 M10-08: This is the best deal ever
I want to split that up into 4 columns ( prefrebely in RPD) . 1 column will be 1.1.01, 2nd column as just M or Q ( Depending upon the data) . 3rd Column as M10-08. 4th Column as the vervbage ( eg : this is the best deal ever).
How would i do this. ANy help will be appreciated.
thanksHi user599926,
The Business Model and Mapping Layer (logical layer) in the RPD is the right place for this kind of change. Here's what you do
1) Import your physical table into the RPD
2) Drag and drop that table into a BMM folder
4) Right click on the logical table and select "New Object" -> "Logical Column..."
5) Give the column a name
6) Click on the Data Type tab
7) Double click on the Logical Table Source (LTS) *Make sure "Show all logical sources" is checked
8) Uncheck "Show mapped columns"
9) Check "Show unmapped columns"
10) you should now only see your new column.
11) Click on the three dots "..." next to the name of the column.
12) Use the SUBSTRING() function on your original field. E.g. SUBSTRING(FIELD1 FROM 1 FOR 6)
13) Hit OK
14) Hit OK
15) Repeat steps 4-14 for 2nd ,3rd and 4th column. They will just have a different FROM and FOR number.
Good luck!
-Joe -
Avoid splitting of columns ALV report while download output to Excel sheet
Hi friends,
I have 170 columns in my ALV report
while downloading the report to Excel sheet
the column descriptions and values are splitting in two lines.
How can i avoid the problem.
before calling REUSE_ALV_GRID_DISPLAY function module in my code
for the Layout i assigned LS_LAYOUT-MAX_SIZE = 1023.
but still the problem is not solved.
Please help me in this Issue.
Thanks in Advance,
GaneshHi friends,
I dont want to use and Keyboard shiftcntrl....
or dont want to change any code in ALV report
by simply assigning some value to any of the export parameter in ALV function module
can we achieve the functionality
Thanks in Advance,
Ganesh -
Split CLOB column to improve performance
Hi All,
We have a transactional table which has 3 columns and one among those is CLOB which holds XML data.Inserts are coming at 35K/hr to this table and data will be deleted as soon as job is completed. So anytime the total records in this table will be less than 1000.
The XML data contains binary info of images and the size of each XML file ranges any where between 200KB to 600KB and the elapsed time for each insert varies from 1 to 2 secs depending upon the concurrency. As we need to achieve 125K/hour soon we were planning to do few modifications on table level.
1. Increase the CHUNK size from 8KB to 32KB.
2. Disabling logging for table,clob and index.
3. Disable flashback for database.
4. Move the table to a non default blocksize of 32KB. Default is 8KB
5. Increase the SDU value.
6. Split the XML data and store it on multiple CLOB columns.
We don't do any update to this table. Its only INSERT,SELECT and DELETE operations.
The major wait events I'm seeing during the insert is
1. direct path read
2. direct path write
3. flashback logfile sync
4. SQL*Net more data from client
5. Buffer busy wait
My doubt over here is ,
1. If I allocate a 2G memory for the non default block size and change the clob to CACHE, will my other objects in buffer_cache gets affected or gets aged out fast?
2. And moving this table to a SECUREFILE from BASICFILE will help?
3. Splitting the XML data to insert into different columns in the same table will give a performance boost?
Oracle EE 11.2.0.1,ASM
Thanks,
ArunThanks to all for the replies
@Sybrand
Please answer first whether the column is stored in a separate lobsegment.
No. Table,Index,LOB,LOB index uses the same TS. I missed adding this point( moving to separate TS) as part of table modifications.
@Hemant
There's a famous paper / blog post about CLOBs and Database Flashback. If I find it, I'll post the URL.
Is this the one you are referring to
http://laimisnd.wordpress.com/2011/03/25/lobs-and-flashback-database-performance/
By moving the CLOB column to different block size , I will test the performance improvement it gives and will share the results.
We dont need any data from this table. XML file contains details about finger prints and once the application server completes the job , XML data is deleted from this table.
So no need of backup/recovery operations for this table. Client will be able to replay the transactions if any problem occurs.
@Billy
We are not performing XML parsing on DB side. Gets the XML data from client -> insert into table -> client selects from table -> Upon successful completion of the Job from client ,XML data gets deleted.
Regarding binding of LOB from client side, will check on that side also to reduce round trips.
By changing the blocksize, I can keep db_32K_cache_size=2G and keep this table in CACHE. If I directly put my table to CACHE, it will age out all other operation from buffer which makes things worse for us.
This insert is part of transaction( Registration of a finger print) and this is the only statement taking time as of now compared to other statements in the transaction.
Thanks,
Arun
Maybe you are looking for
-
HELP! How can I shink only one dimension? I need to shrink the width slightly to fit the frame; the program only allows scaling that is proportional, so when I shrink the width the heigh becomes too short. Father Mike
-
Scan a document to adobe reader
how do I scan a document to adobe reader
-
Hi all, I use Oracle Developer Suite 10.1.2.0.2 on XP platform. When I start any form I get this error massage: FRM-40039: Cannot attach library webutil while opening form MYFORM1. I compile webutil.pll (Shift+Ctrl+K and Ctrl+T to generate PLX) and t
-
Bootcamp Installation Questions
Hey everyone! Yesterday i just purchased a retina display macbook pro, im wanting to install windows but there are two things im unsure of. What copy of windows do i need to get? the full? upgrade? would this be it? http://www.microsoftstore.com/stor
-
Suddenly, Flash Player plug-in 10.3 doesn't work
I am using Mac OS X 10.5.8 on my MacBook Pro 2.2 GHz, and just in the last few days, every time I go to one of many websites that contain Flash video, I see the "Missing plug-in" message. This is in Safari 5.0.6. It worked until this weekend! I hav