473,385 Members | 1,813 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,385 software developers and data experts.

Column Concatenation Function?

Dear all,

I would like to ask is these any DB2 function that can concatenation strings
and have grouping capability??

for example,

Tables:T

F1 F2
---- ----
A X
A Y
A Z
B M
B N
B O

SQL: select F1, STRCAT(F2,',') from T group by F1
* STRCAT is a imaginary function ..

Result:
1 2
--- ---------
A X,Y,Z
B M,N,O

Thanks in advance!

Henry
Dec 15 '05 #1
5 4916
kaming wrote:
Dear all,

I would like to ask is these any DB2 function that can concatenation
strings and have grouping capability??

for example,

Tables:T

F1 F2
---- ----
A X
A Y
A Z
B M
B N
B O

SQL: select F1, STRCAT(F2,',') from T group by F1
* STRCAT is a imaginary function ..

Result:
1 2
--- ---------
A X,Y,Z
B M,N,O


Have a look at recursive queries. Examples for your question are posted
here about twice a month at least.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 15 '05 #2
Why do you wish to destroy first normal form (1NF)?

All values in an RDBMS are scalar. What have you disocovered that Dr.
Codd et al missed for the last 30+ years?

Or are you merely violating the basic principle of a tiered
architecture?

The basic principle of a tiered architecture is that display is done in
the front end and never in the back end. This a more basic programming
principle than just SQL and RDBMS.
Oh, if you still want to be bad programmer, use a cursor so you can
control the ordering. There are a lot of kludges like this posted.

Dec 16 '05 #3

--CELKO-- wrote:

<crazy insults snipped>
The basic principle of a tiered architecture is that display is done in
the front end and never in the back end. This a more basic programming
principle than just SQL and RDBMS.


<another useless insult snipped>

Celko, the OP wasn't talking about modeling, he was talking about
querying. Are you saying that this kind of operation should only be
performed in PHP, Java, VB, Python, Ruby, etc? And never in SQL?

Nevermind the performance benefits of doing it in SQL.

Nevermind the opportunity to create a materialized view that could
speed up the operation.

Buck

Dec 16 '05 #4
--CELKO-- wrote:
Why do you wish to destroy first normal form (1NF)?

All values in an RDBMS are scalar. What have you disocovered that Dr.
Codd et al missed for the last 30+ years?

Or are you merely violating the basic principle of a tiered
architecture?

The basic principle of a tiered architecture is that display is done in
the front end and never in the back end. This a more basic programming
principle than just SQL and RDBMS.
Oh, if you still want to be bad programmer, use a cursor so you can
control the ordering. There are a lot of kludges like this posted.

With this type of thinking, why are there any aggregate functions:
count, sum, avg, etc.? Shouldn't they also be achieved in the front end?
An (or several) aggregate function(s) that worked with strings as
opposed to just numbers, would be greatly appreciated. The whole world
does not consist of accountants and statisticians, SQL xxxx standards
not withstanding. In a perfect world, there would be a way to
declare/define user aggregate functions as well as table and scalar
functions, but a new concept, static, might need to be introduced.
Dec 16 '05 #5
No. An aggregate functions return a *scalar value* of a group
characteristic. This concatenation returns a list *structure*. That
list can be in any order unless you use a cursor and procedural code to
sort it. An aggrgate function that returns an array would also be
wrong becuase it woudl violate 1NF and the results would not be a
table.
there would be a way to declare/define user aggregate functions as well as table and scalar functions, but a new concept, static, might need to be introduced. <<


You would be surprised with what you can do using nested function calls
and expressions right now.

People that argue it is cheaper to do this kind of reporting in the
database forget about the cost of searching, string handling and
disassembly in the front end. The real trick is to have a reporting
tier that holds the data and does the dirt work. The transfer of data
from the RDBMS to the middle tier can be reduced and compressed so that
you do not waste time.

Dec 17 '05 #6

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

Similar topics

5
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
0
by: Nick Heppleston | last post by:
I have a concatenation problem and I was wondering if somebody might be able to offer some help :-) I have the following table structure holding product long descriptions: Part...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
3
by: graphicsxp | last post by:
Hi, I have a SQL stored procedure which looks like that: SELECT @QuerySQL = 'SELECT as LookupField, G.GroupDesc + ' + '" : "' + ' + as DescField FROM ' + 'JOIN ItemGrouping IG on IG.CatID...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
2
by: John | last post by:
Hi I have an email column in a table. How can I turn values in the column for all records into a single string with each email separated by a ;? Thanks Regards
8
by: kingskippus | last post by:
I don't know if this is possible, but I haven't been able to find any information. I have two tables, for example: Table 1 (two columns, id and foo) id foo --- ----- 1 foo_a 2 foo_b
6
by: NarutoFanatic | last post by:
Hi! I need help in MS ACCESS, I need to create a query that could move different rows into another column. More like concatenation but in a different column rather than in one column. Example: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.