473,473 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to split the contents of a column

The SQL statement below returns the single value "8000k/1000k".

select col1 from table1 fetch first 1 row only for read only with ur;

COL1
----------------
8000k/1000k

Now, this is actually two values held in the same column (horrible
database design, I know).

What I am trying to write is an SQL statement that will split this
single column (varchar(16)) and return two integer values - 8000 and
1000. So, the field delimiter is '/' and I want to strip off the 'k'
characters.

Any idea how I can achieve this with SQL (DB2 v8).

Thanks.

Oct 2 '07 #1
3 7932
On Oct 2, 3:23 am, Desmodromic <davies...@yahoo.com.auwrote:
The SQL statement below returns the single value "8000k/1000k".

select col1 from table1 fetch first 1 row only for read only with ur;

COL1
----------------
8000k/1000k

Now, this is actually two values held in the same column (horrible
database design, I know).

What I am trying to write is an SQL statement that will split this
single column (varchar(16)) and return two integer values - 8000 and
1000. So, the field delimiter is '/' and I want to strip off the 'k'
characters.

Any idea how I can achieve this with SQL (DB2 v8).
As usual it depends :-) If you can assume that there is always 2
values, and that they always end with a letter you can use something
like:

db2 "with T (c) as ( values '8000k/1000k' ) select c, substr(c,
1,locate('/',c)-2), substr(c,locate('/',c)+1,
length(substr(c,locate('/',c)+1)) - 1) from T"

C 2 3
----------- ----------- -----------
8000k/1000k 8000 1000

1 record(s) selected.

If you are going to use it a lot, stuff it in a function or a view. As
you noticed your self, the design of the table has improvement
potential :-)
HTH
/Lennart

Thanks.

Oct 2 '07 #2
hi!...i'm trying to use substr(c,locate('/',c)+2) in DB2 ..but DB2
show me this error message : unautorizated name "LOCATE" ..are you sur
that is for DB2?????...
thanks

Oct 4 '07 #3
On Oct 4, 6:32 pm, pchav...@gmail.com wrote:
hi!...i'm trying to use substr(c,locate('/',c)+2) in DB2 ..but DB2
show me this error message : unautorizated name "LOCATE" ..are you sur
that is for DB2?????...
What version of db2 are you using, what's you query, and what error
message are you getting?

/Lennart
Oct 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Prit | last post by:
Hi everyone I guess this should be a simple question for the gurus I have a Data in a column which is to be places in 2 columns instead of one. How do i go about doing it in MS SQL server? Could...
2
by: needin4mation | last post by:
Hi, thanks for any help here: SqlCommand cmd = new SqlCommand("SELECT categories FROM catalog" conn); rdr = cmd.ExecuteReader(); String temp; while (rdr.Read()) { temp = rdr;...
3
by: KamaleshwariP | last post by:
Hi at work i need to split one column based on the commas.In one column there are lot of values which are separated by commas.Can u please help me to write a SQL query for teh same?
2
by: Dscar | last post by:
Hi, I am a beginner in ACCESS, I've imported data into access, and then realized that I need to split the information in one of my columns into 2 columns. the information looks like this:...
5
by: sanbala | last post by:
hi.. i have one field like as answer. it contains both integer and string values. i want to split into column as ans_id,ans_text.ans_id contain numeric value of answer. ans_text contain text value...
9
peeaurjee
by: peeaurjee | last post by:
Hi! I have a column in the Table of my database named 'Duration of Labour Contract' and inside this i have entered the data like that: 01/01/2006 - 31/12/2009 Now i need to split this...
3
by: Madhur | last post by:
I would like to know the best way of generating filter of two files based upon the following condition I have two files. Contents of the first file is File 1 abc def hij asd sss lmn hig pqr...
3
by: supermen | last post by:
to all, how to split a column into 5 coloumn. e.g column= 1 2 1 3 4 into colomn1 = 1 colomn2 = 2 colomn3 = 1 colomn4 = 3 colomn5 = 4
3
by: mcl | last post by:
I wish to create a standard 3 column CSS page, but my centre contents column is quite long. I have included Anchor Name Tags in the long column and provided a navigation / Table of contents in the...
0
by: PLALS | last post by:
Hi All, I am looking for the recursive function in C# for spliting the single row data into multiple row, I have a data table in C# and the table contents data like column --> :| A | B ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.