473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Possible to parse a column in a Select statement?

I have a column called SEGMENTED_BLOCK sample data:
X,X,X
XX,XX,XX,
TYZC123456,X,X,
TOYZ654321,1234,777777

I need to do something that has the effect of

SELECT
(stuff before first comma) as FIRST_ITEM,
(stuff after first comma, but before second) as NEXT_ITEM,
(stuff after second comma but before third(if any)) as THIRD_ITEM
FROM SEGMENT_XREF
WHERE LOOKUP_ITEM = 12345
ORDER BY FIRST_ITEM

FIRST_ITEM is pretty easy, but it gets uglier fast.
My attempts are horrendously ugly nested checkindex and substring statements.
Is there an easier way?
Jul 20 '05 #1
2 2230
Hi

Charindex is the usual way to segment strings even when it is like:
http://www.users.drew.edu/skass/sql/...nction.sql.txt

John
"grok" <jo**********@verizon.net> wrote in message
news:y3*****************@nwrddc04.gnilink.net...
I have a column called SEGMENTED_BLOCK sample data:
X,X,X
XX,XX,XX,
TYZC123456,X,X,
TOYZ654321,1234,777777

I need to do something that has the effect of

SELECT
(stuff before first comma) as FIRST_ITEM,
(stuff after first comma, but before second) as NEXT_ITEM,
(stuff after second comma but before third(if any)) as THIRD_ITEM
FROM SEGMENT_XREF
WHERE LOOKUP_ITEM = 12345
ORDER BY FIRST_ITEM

FIRST_ITEM is pretty easy, but it gets uglier fast.
My attempts are horrendously ugly nested checkindex and substring
statements.
Is there an easier way?
Jul 20 '05 #2
see
http://www.nigelrivett.net/f_GetEntryDelimiitted.html

It's a function that returns entries from a csv string.
I use it for gettig fields from data after bulk inserting but it can be
used for a single string too.

Nigel Rivett
www.nigelrivett.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

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

Similar topics

22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
14
by: php newbie | last post by:
I am getting error messages when I try to delete from a table using the values in the table itself. The intent is to delete all rows from TableA where col_2 matches any of the col_1 values. ...
5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
8
by: Uros | last post by:
Hello! I have problem with my function and I can find what's wrong. WARNING: Error occurred while executing PL/pgSQL function fn_insert_entry_pending WARNING: line 26 at SQL statement...
13
by: Alison Givens | last post by:
....... that nobody knows the answer. I can't imagine that I am the only one that uses parameters in CR. So, my question again: I have the following problem. (VB.NET 2003 with CR) I have a...
3
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select...
11
by: Timofmars | last post by:
I'm try to Unload DB2 data from a table into a record sequential file on NT. I can an unload on Mainframe, but it doesn't seem to be an option in NT. In NT, all I can do is export/import. I can...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
3
by: Leighya | last post by:
Im currently working on this xml file but when i load it to Mozilla, i got an error "Error Loading Stylesheet: Xpath parse failure: invalid variable name" It loads on IE properly. Only with the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.