473,769 Members | 5,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select distinct() with XML query functions.

Hi all.
I'm really stuck with getting the right output from a XML query.

Given this structure:

create table GENCMP.SCRIPTS
(
SCRIPT_ID CHAR(10) not null,
PAGE_NO INTEGER not null
);

CREATE unique INDEX GENCMP.SCRIPTS_ 0 on GENCMP.SCRIPTS
(SCRIPT_ID, PAGE_NO) pctfree 2 allow reverse scans ;
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('CUSTCARE',
1);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('CUSTCARE',
2);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('LEAD', 1);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('LEAD', 2);
What query do I use to get the following output:

<SCRIPTS>
<SCRIPT>CUSTCAR E</SCRIPT>
<SCRIPT>LEAD</SCRIPT>
</SCRIPTS>
I just can not get it happening.

I would appreciate any support/help.

-Chris

Feb 15 '07 #1
3 12876
ch****@warpspee d.com.au wrote:
Hi all.
I'm really stuck with getting the right output from a XML query.

Given this structure:

create table GENCMP.SCRIPTS
(
SCRIPT_ID CHAR(10) not null,
PAGE_NO INTEGER not null
);

CREATE unique INDEX GENCMP.SCRIPTS_ 0 on GENCMP.SCRIPTS
(SCRIPT_ID, PAGE_NO) pctfree 2 allow reverse scans ;
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('CUSTCARE',
1);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('CUSTCARE',
2);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('LEAD', 1);
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO) values ('LEAD', 2);
What query do I use to get the following output:

<SCRIPTS>
<SCRIPT>CUSTCAR E</SCRIPT>
<SCRIPT>LEAD</SCRIPT>
</SCRIPTS>
How about this:

SELECT XMLSERIALIZE(XM LELEMENT(NAME "SCRIPTS",
XMLELEMENT(NAME "SCRIPT", script_id)) AS VARCHAR(2000))
FROM ( SELECT DISTINCT script_id
FROM scripts ) AS t
That's on DB2 V9.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Feb 15 '07 #2
On Feb 15, 5:44 pm, Knut Stolze <sto...@de.ibm. comwrote:
>
How about this:

SELECT XMLSERIALIZE(XM LELEMENT(NAME "SCRIPTS",
XMLELEMENT(NAME "SCRIPT", script_id)) AS VARCHAR(2000))
FROM ( SELECT DISTINCT script_id
FROM scripts ) AS t

That's on DB2 V9.
Thank you so much! I could not work out where the distinct would fit
in. Brain fade me.

This is what I got working under V8:

SELECT XMLSERIALIZE(CO NTENT XMLELEMENT(NAME "SCRIPTS",
XMLAGG(
XMLELEMENT( NAME "SCRIPT", SCRIPT_ID ) ) ) AS
VARCHAR(80) ) AS RESULT
FROM ( select distinct script_id from GENCMP.SCRIPTS ) as T;

RESULT
--------------------------------------------------------------------------------
<SCRIPTS><SCRIP T>CUSTCARE </SCRIPT><SCRIPT> LEAD </SCRIPT></
SCRIPTS>

1 record(s) selected.

:-))))))))))))))) )

Danke.

-Chris

Feb 15 '07 #3
ch****@warpspee d.com.au wrote:
On Feb 15, 5:44 pm, Knut Stolze <sto...@de.ibm. comwrote:
>>
How about this:

SELECT XMLSERIALIZE(XM LELEMENT(NAME "SCRIPTS",
XMLELEMENT(NAME "SCRIPT", script_id)) AS VARCHAR(2000))
FROM ( SELECT DISTINCT script_id
FROM scripts ) AS t

That's on DB2 V9.

Thank you so much! I could not work out where the distinct would fit
in. Brain fade me.

This is what I got working under V8:

SELECT XMLSERIALIZE(CO NTENT XMLELEMENT(NAME "SCRIPTS",
XMLAGG(
XMLELEMENT( NAME "SCRIPT", SCRIPT_ID ) ) ) AS
VARCHAR(80) ) AS RESULT
FROM ( select distinct script_id from GENCMP.SCRIPTS ) as T;

RESULT
--------------------------------------------------------------------------------
<SCRIPTS><SCRIP T>CUSTCARE </SCRIPT><SCRIPT> LEAD </SCRIPT></
SCRIPTS>

1 record(s) selected.

:-))))))))))))))) )
Right. I didn't try this myself, so I missed the syntax error (missing
CONTENT keyword) and the XMLAGG function. Thanks for correcting that.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Feb 16 '07 #4

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

Similar topics

2
4407
by: dr. zoidberg | last post by:
Hello, I'm trying to select all distinct years from a unixtimestamp field in MySQL database. I have a query: SELECT DISTINCT YEAR(date_field) As theYear FROM table but it gives me an empty array. What am I doing wrong? TNX
1
3608
by: Perre Van Wilrijk | last post by:
Hi, I have a table as following aa Text1 aa, p@xxx.be, 15267 aa Text1 aa, p@xxx.be, 16598 aa Text1 aa, p@xxx.be, 17568 aa Text2 aa, p@xxx.be, 25698 aa Text3 aa, x@zzz.be, 12258
9
10905
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my table:- ID Ref Name DATE 1 AAA Joe 1/2 2 BBB Ken 1/2 3 AAA Len 6/3
6
5557
by: John M | last post by:
Hi, The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of students who have been involved in incidents. Some may appear several times, hence the Distinct. However, thelist generated should still be sorted by Surname. When I add Order by I'm told it conflict with the 'Distinct'. Surely it does not? SELECT DISTINCT ., . & " " & . FROM...
18
3065
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are only returning one record. She states that with disctinct the query stops as soon as it finds a matching record. Both of us are relative novices in database theory (obviously). Can someone help settle this?
3
5657
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada Inc
10
5294
by: Farmer | last post by:
Hello Folks, can anybody tell me how to do the following very simple thing: I have a table that has say departments, divisions and units of an organisation and what i am trying to do is find a divison. One department has many divisions, and one division many units. I am think therefore a SELECT DISTINCT query on the division would make sense and to put my search criteria for department on the WHERE. Of course that doesnt work since you...
3
3088
lwwhite
by: lwwhite | last post by:
I've got a a datasheet subform that gets its data from a SELECT DISTINCT query. The data is not editable. When I remove the DISTINCT qualifier from the query, the data is editable, but of course I get a much longer record set. I understand why Access doesn't want to let the data be editable in this situation, but I'm hoping there is a way to circumvent this restriction. Thanks for any suggestions. (Access 2003)
8
13540
by: cmrhema | last post by:
Hello I am preparing an application where I have different data stored in an array eg. Dim Vehicle(100) as String In this array different values are stored in an ordered manner. eg. Vehicle(0)="Tata" Vehicle(1)="Tata" Vehicle(2)="Tata" Vehicle(3)="Maruti" Vehicle(4)="Maruti"
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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 we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.