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

SQL output, do I need recursive SQL todo this?

Simple example how can I produce a list of tables and their indexes in this
format:

Col1 Col2

Tab1 Index1forTab1
Index2forTab1
Index3forTab1

Tab2 Index1forTab2

Tab3 Index1forTab3
Index2forTab3

you get the idea, I can obviously just do a normal select from
syscat.indexes and do a group by tabname but I wanted to know if it was
possible to neaten the output so that the tabname comes out only once. I
figured I would need some recursion todo this so have been looking for some
examples.

cheers.
Nov 12 '05 #1
3 2622
Lee Dilworth wrote:
Simple example how can I produce a list of tables and their indexes in
this format:

Col1 Col2

Tab1 Index1forTab1
Index2forTab1
Index3forTab1

Tab2 Index1forTab2

Tab3 Index1forTab3
Index2forTab3

you get the idea, I can obviously just do a normal select from
syscat.indexes and do a group by tabname but I wanted to know if it was
possible to neaten the output so that the tabname comes out only once. I
figured I would need some recursion todo this so have been looking for
some examples.


You don't need recursion. Just number the rows in each group and then
return the table name only for those rows where the row number equals 1.
Something like this:

SELECT CASE
WHEN rn = 1 THEN table_name
ELSE NULL
END,
index_name
FROM ( SELECT tabname, idxname, row_number() over(partition by tabname)
FROM syscat.indexes ) AS t(table_name, index_name, rn)

p.s: I'm not 100% sure on the exact syntax of the row_number function,
though.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
thanks !!
Nov 12 '05 #3

"Knut Stolze" <st****@de.ibm.com> wrote in message
news:cs**********@fsuj29.rz.uni-jena.de...
Lee Dilworth wrote:
Simple example how can I produce a list of tables and their indexes in
this format:

Col1 Col2

Tab1 Index1forTab1
Index2forTab1
Index3forTab1

Tab2 Index1forTab2

Tab3 Index1forTab3
Index2forTab3

you get the idea, I can obviously just do a normal select from
syscat.indexes and do a group by tabname but I wanted to know if it was
possible to neaten the output so that the tabname comes out only once. I
figured I would need some recursion todo this so have been looking for
some examples.


You don't need recursion. Just number the rows in each group and then
return the table name only for those rows where the row number equals 1.
Something like this:

SELECT CASE
WHEN rn = 1 THEN table_name
ELSE NULL
END,
index_name
FROM ( SELECT tabname, idxname, row_number() over(partition by tabname)
FROM syscat.indexes ) AS t(table_name, index_name, rn)

p.s: I'm not 100% sure on the exact syntax of the row_number function,
though.

Another possible solution to this problem is to use QMF. QMF has always had
the ability to prevent the duplication of a column (or columns) value from
row to row. I just looked at the QMF V8 Info Center to refresh my memory and
found it right away: on FORM.MAIN you say OUTLINE? ==> YES; QMF takes care
of the rest. This is a very basic and useful function that has been in QMF
from Day One. (You can also control the appearance further with
FORM.OPTIONS.)

Of course this doesn't help much if you don't have QMF ;-)

Rhino
Nov 12 '05 #4

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

Similar topics

0
by: Vissu | last post by:
Hi, I have tkprof output with non-recursive and recursive overall timings. I understand that when PLSQL calls sql statements it is considered as recursive time. My question is the time being...
2
by: Soren Kuula | last post by:
Hi, I'm trying to teach myself a little XSL. I have made up an XML model of a consed list, like : <list> <car>a</car> <cdr> <list> <car>b</car>
1
by: joy_julia446 | last post by:
Hi there, I would like to print my result as below in an output file. I would appreciate if someone can give me some advice. RESULT ClassA,96.678,88.196,8.048,-0.233,456.231,5.890, 1...
9
by: Diane | last post by:
Could you please explain me how can I output nested strings? Here is an example: "adsd{rfkm}xcv" The output should start from the inner parentheses, such as: dfF rfkm
0
by: 14Dallas | last post by:
Hi, I have been working with another programmer to write this code. I haven't written code in years - DBase III and Pascal - anyways, back to my code question. The program opens a file and...
9
by: seberino | last post by:
I'm a compiler newbie and curious if Python grammar is able to be parsed by a recursive descent parser or if it requires a more powerful algorithm. Chris
3
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never...
1
by: nelly12 | last post by:
how do i save my C program output in a file for example for (i = 0; i < number_of_tasks; i++) { INFO2("Sending \"%s\" to \"%s\"", todo->name, ...
4
by: Christopher | last post by:
How would I go about indenenting for each level of recursion, if I am trying to output the contents of a class which contains its own type? where AttributeGroupMap is typdef...
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: 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: 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.