473,408 Members | 2,832 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,408 software developers and data experts.

Advance SQL question


Hello everybody,

i have a advance question about a specific sql problem:

My table A have for example 3 columns.
in the third column are words seperated by ~.
ID COL2 COL3
--------------
1 ab test~dummy~ddd
2 cd testdata2~sjhfdg~sdf
3 ef sd~test
4 gh sd~cv

Now i want two lists:

1.) used Values for column 3:

Values
------
test
dummy
ddd
testdata2
sjhfdg
sdf
sd
cv

2.) used values plus ID
Value ID
----------
test 1
test 3
sd 3
sd 4
cv 4
dummy 1
....

Is it posible to produce such a list with nearly one SQL -Statement or with
temporaly tables ?
Thanks in advance

T.Kindermann
Database Administrator
--
--------------------------------------------------------------------------
Thomas Kindermann
E-MAIL: Reply to TKINDER<x>@GMX.DE without <x>
Jul 23 '05 #1
2 2072
Thomas Kindermann wrote:
Is it posible to produce such a list with nearly one SQL -Statement ?


Yes, it is possible:

SELECT DISTINCT substring('~' + COL3 + '~', Number + 1,
charindex('~', '~' + COL3 + '~', Number + 1) - Number - 1) AS Value
FROM (
SELECT TOP 250 number
FROM master..spt_values WHERE number>0
GROUP BY number ORDER BY number
) Numbers, TheTable
WHERE Number <= len('~' + COL3 + '~') - 1
AND substring('~' + COL3 + '~', Number, 1) = '~'

SELECT ID, substring('~' + COL3 + '~', Number + 1,
charindex('~', '~' + COL3 + '~', Number + 1) - Number - 1) AS Value
FROM (
SELECT TOP 250 number
FROM master..spt_values WHERE number>0
GROUP BY number ORDER BY number
) Numbers, TheTable
WHERE Number <= len('~' + COL3 + '~') - 1
AND substring('~' + COL3 + '~', Number, 1) = '~'

This queries work with up to 250 words in each row.

However, it may be better to use other ways. For more informations, see
this excellent article by Erland Sommarskog, SQL Server MVP:
http://www.sommarskog.se/arrays-in-sql.html#tblnum-core

Razvan

Jul 23 '05 #2
Am 23 Jun 2005 02:39:18 -0700 schrieb Razvan Socol:
Thomas Kindermann wrote:
[1 zitierte Zeile ausgeblendet]


Yes, it is possible:

SELECT DISTINCT substring('~' + COL3 + '~', Number + 1,
charindex('~', '~' + COL3 + '~', Number + 1) - Number - 1) AS Value
FROM (
SELECT TOP 250 number
FROM master..spt_values WHERE number>0
GROUP BY number ORDER BY number
) Numbers, TheTable
WHERE Number <= len('~' + COL3 + '~') - 1
AND substring('~' + COL3 + '~', Number, 1) = '~'

SELECT ID, substring('~' + COL3 + '~', Number + 1,
charindex('~', '~' + COL3 + '~', Number + 1) - Number - 1) AS Value
FROM (
SELECT TOP 250 number
FROM master..spt_values WHERE number>0
GROUP BY number ORDER BY number
) Numbers, TheTable
WHERE Number <= len('~' + COL3 + '~') - 1
AND substring('~' + COL3 + '~', Number, 1) = '~'

This queries work with up to 250 words in each row.

However, it may be better to use other ways. For more informations, see
this excellent article by Erland Sommarskog, SQL Server MVP:
http://www.sommarskog.se/arrays-in-sql.html#tblnum-core

Razvan

GENIAL SUPER,

you are my good ;-))))))))
Thanks

Thomas
--
--------------------------------------------------------------------------
Thomas Kindermann
E-MAIL: Reply to TKINDER<x>@GMX.DE without <x>
Jul 23 '05 #3

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

Similar topics

2
by: solartimba | last post by:
I am using the advance() auxiliary STL iterator function to move a map iter forward, but I read that there is no check to keep the iter from pointing past the end of the map. How is this problem...
3
by: david | last post by:
HI! Im trying to make "HTML form" into automatic. 1. If I get 18 numbers like: A B C D E F . . . . 2. How can I put those 18 numbers automatically into 6 numbers format like: A B C D E F
1
by: John | last post by:
Hi again, I appreciate all the advice I've gotten so far. My question this time is whether there's a way to make the row height equal to the column width when you don't know in advance what...
0
by: Hai Nguyen | last post by:
Hi all I'm trying to create form (can be anything, but a prefer it's a datagrid). It should look like this Header 1 Header 2 Header3 Header4 Header5 (textbox) ...
3
by: zzzbla | last post by:
Hi, I need to attach a javascript function I wrote to the onChange event of a <select> tag. However, I'm using a 3rd party tool that creates the html files - it only lets me add bits of html to...
5
by: A. Farber | last post by:
Hello, I call readv() and writev() in several spots of a program which I run under Linux, OpenBSD and Cygwin. Since it always the same way (check the return value; then check errno and retry if...
16
by: vicky | last post by:
hi all, please send me the link of tutorial of advance programming in c. which help me to clear all compilation problems and also help me in my projects. thanks,
4
by: sarika | last post by:
Which group should i join for learning advance ajax plz help
3
by: xsort | last post by:
Hi, everybody. using ubuntu. I really need an advance tutorial of XSub, all tutorials that I saw were very basic. I need to use C libraries; but some of this libraries are generated dynamically...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.