Author |
Message
|
ydeonia |
Posted: Mon May 13, 2013 1:23 am Post subject: Else statement for NUll select statement |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Hi
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt] = THE (SELECT THE(SELECT S.*:Property.*:NameValue AS TyrePatternCd FROM T.*:Specification[] AS S
WHERE S.Property.NameValue.(XMLNSC.Attribute)Name='PATTERN' AND S.(XMLNSC.Attribute)Type = 'PHYSICAL') AS product_Info
FROM itemMaster.*:ItemMasterHeader[] AS T );
|
In above statement if the Select comes null it makes the tree null, How can I make the else statement so that if the above statment comes NULL it shows below output
Quote: |
ELSE SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.value = NULL; |
|
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 5:28 am Post subject: Re: Else statement for NUll select statement |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
In above statement if the Select comes null it makes the tree null, How can I make the else statement so that if the above statment comes NULL it shows below output
Code: |
ELSE SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.value = NULL; |
|
Well strictly speaking if the SELECT returns a NULL then you obviously assign a NULL. In that case, and the case you quote where you specifically assign a NULL with a SET statement you're not setting TyrePatternCd.value to NULL, you're deleting it (which you may consider the same thing).
If you want to test for a NULL and set a different value when you detect one, COALESCE is the way to go. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 6:46 am Post subject: Re: Else statement for NUll select statement |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Vitor wrote: |
ydeonia wrote: |
In above statement if the Select comes null it makes the tree null, How can I make the else statement so that if the above statment comes NULL it shows below output
Code: |
ELSE SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.value = NULL; |
|
Well strictly speaking if the SELECT returns a NULL then you obviously assign a NULL. In that case, and the case you quote where you specifically assign a NULL with a SET statement you're not setting TyrePatternCd.value to NULL, you're deleting it (which you may consider the same thing).
If you want to test for a NULL and set a different value when you detect one, COALESCE is the way to go. |
Thanks
in the above statement the select query when fetches the values makes xml tree as desired
Code: |
<root>
<product_info>
<TyrePatternCd>value</TyrePatternCd.
</product_info>
</root>
|
but when the value comes as NULL it makes who tree as NULL.
So it shows like
I want it to keep the structure as it is liek below .
Code: |
<root>
<product_info>
<TyrePatternCd/>
</product_info>
</root> |
So how can I maintain the tree value in COALESCE. Even I thought of same. But what should I write in default value since the output tree is select and required when is different. |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon May 13, 2013 6:51 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Perhaps you might like to look at something like
Code: |
SET myParam VALUE = NULL;
|
That does not delete the tree element. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 7:06 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
smdavies99 wrote: |
Perhaps you might like to look at something like
Code: |
SET myParam VALUE = NULL;
|
That does not delete the tree element. |
I didnt get your point anyway thanks alot. How can I use the above in below select query
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt] = THE (SELECT THE(SELECT S.*:Property.*:NameValue AS TyrePatternCd FROM T.*:Specification[] AS S
WHERE S.Property.NameValue.(XMLNSC.Attribute)Name='PATTERN' AND S.(XMLNSC.Attribute)Type = 'PHYSICAL') AS product_Info
FROM itemMaster.*:ItemMasterHeader[] AS T ); |
Bacause if this select query becomes NULL I want to keep the tree like
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd
|
Since the same output tree is comes from the select query in above |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 7:32 am Post subject: Re: Else statement for NUll select statement |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
I want it to keep the structure as it is liek below .
Code: |
<root>
<product_info>
<TyrePatternCd/>
</product_info>
</root> |
|
Ok, that's a subtly different thing. The TyrePatternCd tag in the above example is not null, it's empty and you can't create an empty tag with a SET statement.
From your original post:
ydeonia wrote: |
In above statement if the Select comes null it makes the tree null, How can I make the else statement so that if the above statment comes NULL it shows below output
Code: |
ELSE SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.value = NULL; |
|
You need something like:
Code: |
ELSE CREATE NEXTSIBLING OF OutputRoot.XMLNSC.root.row[rowCnt].product_Info NAME 'TyrePatternCd' |
Other code solutions are undoubtably possible and may be better. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 7:39 am Post subject: Re: Else statement for NUll select statement |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Vitor wrote: |
ydeonia wrote: |
I want it to keep the structure as it is liek below .
Code: |
<root>
<product_info>
<TyrePatternCd/>
</product_info>
</root> |
|
Ok, that's a subtly different thing. The TyrePatternCd tag in the above example is not null, it's empty and you can't create an empty tag with a SET statement.
From your original post:
ydeonia wrote: |
In above statement if the Select comes null it makes the tree null, How can I make the else statement so that if the above statment comes NULL it shows below output
Code: |
ELSE SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.value = NULL; |
|
You need something like:
Code: |
ELSE CREATE NEXTSIBLING OF OutputRoot.XMLNSC.root.row[rowCnt].product_Info NAME 'TyrePatternCd' |
Other code solutions are undoubtably possible and may be better. |
My problem what condition I can make the else statement ?
On what condition of that select query I make the else statment .
Code: |
S.Property.NameValue.(XMLNSC.Attribute)Name='PATTERN' AND S.(XMLNSC.Attribute)Type = 'PHYSICAL' |
I am checking for query and any of the above AND comes false, it make tree like that. So I am stuck that on what condition I can make if anyoneof teh abovce comes false, set else |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 7:50 am Post subject: Re: Else statement for NUll select statement |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
So I am stuck that on what condition I can make if anyoneof teh abovce comes false, set else |
Why an else? Why not have the immediately following statement:
Code: |
IF OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd IS NULL THEN CREATE NEXTSIBLING OF OutputRoot.XMLNSC.root.row[rowCnt].product_Info NAME 'TyrePatternCd' |
_________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 8:11 am Post subject: Re: Else statement for NUll select statement |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Vitor wrote: |
ydeonia wrote: |
So I am stuck that on what condition I can make if anyoneof teh abovce comes false, set else |
Why an else? Why not have the immediately following statement:
Code: |
IF OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd IS NULL THEN CREATE NEXTSIBLING OF OutputRoot.XMLNSC.root.row[rowCnt].product_Info NAME 'TyrePatternCd' |
|
Oh wow .. I didnt thinkof that Thanks alot . One more issue is with below select query
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt] = THE (SELECT THE(SELECT S.*:Property.*:NameValue AS TyrePatternCd FROM T.*:Specification[] AS S
WHERE S.Property.NameValue.(XMLNSC.Attribute)Name='PATTERN' AND S.(XMLNSC.Attribute)Type = 'PHYSICAL') AS product_Info
FROM itemMaster.*:ItemMasterHeader[] AS T ); |
The output is like
Code: |
<root>
<product_info>
<TyrePatternCd Name="PATTERN">value</TyrePatternCd>
</product_info>
</root>
|
How can I overcome the Attribute
in output
It should look like
Code: |
<root>
<product_info>
<TyrePatternCd>value</TyrePatternCd>
</product_info>
</root>
|
|
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 8:15 am Post subject: Re: Else statement for NUll select statement |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
How can I overcome the Attribute
in output
It should look like
Code: |
<root>
<product_info>
<TyrePatternCd>value</TyrePatternCd>
</product_info>
</root>
|
|
Well you know perfectly well that setting NULL to something deletes it because that's why you opened this thread. So how come:
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd.Name =NULL |
didn't occur to you? Possibly as an ELSE to the IF statement above? So you either create one if it wasn't there, and remove the attribute from one copied over? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 8:28 am Post subject: Re: Else statement for NUll select statement |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Vitor wrote: |
didn't occur to you? Possibly as an ELSE to the IF statement above? So you either create one if it wasn't there, and remove the attribute from one copied over? |
Very confusing statment from you Sorry
Actually I was two problems in my code. One was if anyone of the where statement comes false. the xml becomes without elements. I am afraid now also I will afec same. I have three select statments like above and if any of the statment become NULL, it make all tree without Elements.
As you advice to have the below
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt] = THE (SELECT THE(SELECT S.*:Property.*:NameValue AS TyrePatternCd FROM T.*:Specification[] AS S
WHERE S.Property.NameValue.(XMLNSC.Attribute)Name='PATTERN' AND S.(XMLNSC.Attribute)Type = 'PHYSICAL') AS product_Info
FROM itemMaster.*:ItemMasterHeader[] AS T );
IF OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd IS NULL THEN CREATE NEXTSIBLING OF OutputRoot.XMLNSC.root.row[rowCnt].product_Info NAME 'TyrePatternCd'
|
What if I have another select query like this and if any of the select query comes NULL it make all tree NULL , it wont check of other select has value or not
the other problem is that mentioned below , I am getting the Attribute from where clause in output |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 8:35 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
There will come a point where you can't use a single SELECT to copy all or part of a tree over, but need a reference and an amount of user code to handle all the null/not null conditions and combinations you encounter.
It sounds like you might have reached that point. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 8:43 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Vitor wrote: |
There will come a point where you can't use a single SELECT to copy all or part of a tree over, but need a reference and an amount of user code to handle all the null/not null conditions and combinations you encounter.
It sounds like you might have reached that point. |
Yeah .. truely speaking I want to learn for reference with example. Can you please refer me good tutorial on that |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 13, 2013 8:51 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
Yeah .. truely speaking I want to learn for reference with example. Can you please refer me good tutorial on that |
Any of the ESQL samples will show that _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon May 13, 2013 9:16 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I find the AS clause of the CREATE statement to be very handy. |
|
Back to top |
|
 |
|