Hi All,
I've been struggeling with this for a while now, and I was
wondering if anyone could help me.
given:
drop table GENCMP.SCRIPTS;
--=============== =============== =============== =============== ==
-- Table: SCRIPTS
--=============== =============== =============== =============== ==
create table GENCMP.SCRIPTS
(
SCRIPT_ID CHAR(10) not null,
PAGE_NO INTEGER not null,
EFFECTIVE_FROM DATE not null,
EFFECTIVE_TO DATE not null,
USERID CHAR(8) not null,
PUBLISHED CHAR(1) not null,
SCRIPT_TEXT CLOB(32K) LOGGED NOT COMPACT NOT
NULL
);
CREATE unique INDEX GENCMP.SCRIPTS_ 0 on GENCMP.SCRIPTS
(SCRIPT_ID, PAGE_NO, EFFECTIVE_TO) pctfree 2 allow
reverse scans ;
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO, EFFECTIVE_FROM,
EFFECTIVE_TO, USERID, PUBLISHED, SCRIPT_TEXT) values ('CUSTCARE', 1,
'2006-01-01', '9999-12-31', 'APCPG', 'N', 'asd1');
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO, EFFECTIVE_FROM,
EFFECTIVE_TO, USERID, PUBLISHED, SCRIPT_TEXT) values ('CUSTCARE', 2,
'2006-01-01', '9999-12-31', 'APCPG', 'N', 'asd2');
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO, EFFECTIVE_FROM,
EFFECTIVE_TO, USERID, PUBLISHED, SCRIPT_TEXT) values ('CUSTCARE', 3,
'2006-01-01', '9999-12-31', 'APCPG', 'N', 'asd3');
insert into GENCMP.SCRIPTS (SCRIPT_ID, PAGE_NO, EFFECTIVE_FROM,
EFFECTIVE_TO, USERID, PUBLISHED, SCRIPT_TEXT) values ('CUSTCARE', 4,
'2006-01-01', '9999-12-31', 'APCPG', 'N', 'asd4');
select SCRIPT_ID, PAGE_NO, EFFECTIVE_FROM, EFFECTIVE_TO, USERID,
PUBLISHED from GENCMP.SCRIPTS;
You should see:
SCRIPT_ID PAGE_NO EFFECTIVE_FROM EFFECTIVE_TO USERID PUBLISHED
---------- ----------- -------------- ------------ -------- ---------
CUSTCARE 1 01-01-2006 31-12-9999 APCPG N
CUSTCARE 2 01-01-2006 31-12-9999 APCPG N
CUSTCARE 3 01-01-2006 31-12-9999 APCPG N
CUSTCARE 4 01-01-2006 31-12-9999 APCPG N
The query that I have is this:
select XMLSERIALIZE(CO NTENT XMLELEMENT(NAME "SCRIPTS",
XMLAGG(
XMLELEMENT(NAME "SCRIPT",
XMLATTRIBUTES(S CRIPT_ID),
XMLELEMENT(NAME "script_tex t",
XMLATTRIBUTES(P AGE_NO),
SCRIPT_TEXT)
)
)
) AS CLOB
) from gencmp.scripts;
and it generates the following XML:
<SCRIPTS>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="1">asd 1</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="2">asd 2</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="3">asd 3</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="4">asd 4</script_text>
</SCRIPT>
</SCRIPTS>
However, what I need is:
<SCRIPTS>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="1">asd 1</script_text>
<script_text PAGE_NO="2">asd 2</script_text>
<script_text PAGE_NO="3">asd 3</script_text>
<script_text PAGE_NO="4">asd 4</script_text>
</SCRIPT>
</SCRIPTS>
Can anyone help me massage the query into giving me what I need?
TIA,
-Chris 3 2198 ch****@warpspee d.com.au wrote:
SCRIPT_ID PAGE_NO EFFECTIVE_FROM EFFECTIVE_TO USERID PUBLISHED
---------- ----------- -------------- ------------ -------- ---------
CUSTCARE 1 01-01-2006 31-12-9999 APCPG N
CUSTCARE 2 01-01-2006 31-12-9999 APCPG N
CUSTCARE 3 01-01-2006 31-12-9999 APCPG N
CUSTCARE 4 01-01-2006 31-12-9999 APCPG N
The query that I have is this:
select XMLSERIALIZE(CO NTENT XMLELEMENT(NAME "SCRIPTS",
XMLAGG(
XMLELEMENT(NAME "SCRIPT",
XMLATTRIBUTES(S CRIPT_ID),
XMLELEMENT(NAME "script_tex t",
XMLATTRIBUTES(P AGE_NO),
SCRIPT_TEXT)
)
)
) AS CLOB
) from gencmp.scripts;
and it generates the following XML:
<SCRIPTS>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="1">asd 1</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="2">asd 2</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="3">asd 3</script_text>
</SCRIPT>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="4">asd 4</script_text>
</SCRIPT>
</SCRIPTS>
However, what I need is:
<SCRIPTS>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="1">asd 1</script_text>
<script_text PAGE_NO="2">asd 2</script_text>
<script_text PAGE_NO="3">asd 3</script_text>
<script_text PAGE_NO="4">asd 4</script_text>
</SCRIPT>
</SCRIPTS>
If I got this right, then you don't want to have the nested "<SCRIPT>" tags,
right? Therefore, you will have to put the XMLAGG in the right place like
this:
SELECT XMLSERIALIZE(
CONTENT XMLELEMENT(NAME "SCRIPTS",
XMLELEMENT(NAME "SCRIPT",
XMLATTRIBUTES(s cript_id),
XMLAGG(
XMLELEMENT(NAME "script_tex t",
XMLATTRIBUTES(p age_no),
script_text))
ORDER BY page_no))
FROM ...
GROUP BY script_id
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Knut Stolze wrote:
If I got this right, then you don't want to have the nested "<SCRIPT>" tags,
right? Therefore, you will have to put the XMLAGG in the right place like
this:
SELECT XMLSERIALIZE(
CONTENT XMLELEMENT(NAME "SCRIPTS",
XMLELEMENT(NAME "SCRIPT",
XMLATTRIBUTES(s cript_id),
XMLAGG(
XMLELEMENT(NAME "script_tex t",
XMLATTRIBUTES(p age_no),
script_text))
ORDER BY page_no))
FROM ...
GROUP BY script_id
That is basically right. Given that you can not have multiple nested
XMLAGG()'s (is this correct?), I was wondering if I had it in the right
place.
This is the finished, working query:v
SELECT XMLSERIALIZE(CO NTENT
XMLELEMENT(NAME "SCRIPTS",
XMLELEMENT( NAME "SCRIPT",
XMLATTRIBUTES(s cript_id),
XMLAGG(
XMLELEMENT(NAME "script_tex t",
XMLATTRIBUTES(p age_no), script_text)
ORDER BY page_no
) ) ) AS CLOB
)
FROM GENCMP.SCRIPTS
GROUP BY script_id;
Thank you very much for pointing me in the right direction! :-)
It generates this:
<SCRIPTS>
<SCRIPT SCRIPT_ID="CUST CARE ">
<script_text PAGE_NO="1">asd 1</script_text>
<script_text PAGE_NO="2">asd 2</script_text>
<script_text PAGE_NO="3">asd 3</script_text>
<script_text PAGE_NO="4">asd 4</script_text>
</SCRIPT>
</SCRIPTS>
Which is precisely what I wanted.
Thanks again.
-Chris ch****@warpspee d.com.au wrote:
Given that you can not have multiple nested
XMLAGG()'s (is this correct?),
No, that is not correct (unless there are some constraints I don't know
about). Of course, a single subselect can only contain one level of
aggregation. Nested aggregations would immediately raise the question how
to group things on all levels. However, you can use nested subselects and
each subselect can do its own aggregation. That will give you the ability
to aggregate more:
SELECT XMLAGGR(xml_fra gment), ...
FROM ( SELECT XMLAGGR(xml_col umn), ...
FROM ...
GROUP BY ... ) AS t(xml_fragment, ...)
GROUP BY ...
--
Knut Stolze
DB2 Information Integration Development
IBM Germany This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric Kincl |
last post by:
Hello,
I have an array of data in PHP. I would like to insert each member of the
array into it's own row in SQL. The array is of variable length, so it
would have to be dynamic code. How would I go about this? Would I stick
the SQL querry generation and actual querry into a while loop? This would
generate a lot of traffic between the SQL server and the PHP script.
The arrays are each over 1000 members long, however, this is an rare...
|
by: Andreas Fromm |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Im building an user database with many tables keeping the data for the
Address, Phone numbers, etc which are referenced by a table where I keep
the single users. My question is, how do I get the "Id"-value of a newly
inserted address to store it in the referencing user table:
|
by: Jamie Pittman via AccessMonster.com |
last post by:
Does anyone have any suggestion how to create this form. I want to be able
to have form that has two fields and that allow
me to select specific parmeters for my Union Query to Look up? I have a
Querry name that I want to be able to make easy
selections to pull specific data out? I am still new to Access and not
sure how to handle this task? Any help would be greatly appreciated.....
--
Message posted via...
|
by: gurpreet |
last post by:
Hi this is gurpreet,
I know this is a very simple question but still I want
to clear some doubts.
What happens when we compile and link a c-program?
I hope aquite a lot of responses to my querry.
BYE! BYE!
|
by: Clownfish |
last post by:
OK, I'm having a brain freeze.
I have a table like this:
Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
| |
by: jamie |
last post by:
Hello,
I have a SQL question with regards to retrieving data from an Access
DB.
When I use this querry in Access, it works fine, but when I try to get
data, from Access, using the querry it does not reocnize functions like
sum(), left(), or Date().
Can one use a SQL string, just as in Access, from Excell ADO?
|
by: Steve Kiss |
last post by:
Hi. I am developping a site for which one of the pages uses querry strings to pass some parameters. I can use the querry strings if I call the page from a plain html anchor. However, when I add the URL to the sitemap I get the following error:
The 'url' property had a malformed URL
This is the offending URL:
ViewImages.aspx?area=M3000Gallery&areaName=Merlin%203000%20Press%20Brake%20Guarding
I also tried:...
|
by: saddist |
last post by:
Hello,
TRAININGS(ID_TRAINING, TRAINING_NAME)
HOSTED_TRAININGS(ID_HOSTED_TRAINING, ID_TRAINING, DAYS)
EMPLOYEES_ON_TRAININGS(ID_HOSTED_TRAINING)
What I want to do is a querry with sum of days and number of employees for each training
Tried something like that but it returns error "ID_HOSTED_TRAINING is not a part of aggregate function" or something like that:/
SELECT s.TRAINING_NAME AS Szkolenia, Sum(ps.DAYS), (SELECT COUNT(*) FROM...
|
by: dipalichavan82 |
last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry
e.g.
string inputcity=textbox.text;
SqlCommand cmd = new SqlCommand("select * from Customers where city=
'" + inputCity + " ' ";
Don't ever build a query this way!
as this leads to hacking.
instaed do it like this:
|
by: Question123 |
last post by:
Hi
i have one database table Table1.which contains almost 20000000 recordes.
record to this table are inserted through storedprocedure. storedprocedure takes parameter as
"value",
Beginningdate,
Endate .
which will insert one record for each day between Beginning date and EndDate.
Before inserting record i check is record exsist for date,if exsist i will update value otherwise insert new record.
|
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,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |