Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2012-09-02T16:48:30Z by SystemAdmin
chromosome
chromosome
2 Posts
ACCEPTED ANSWER

Pinned topic How to use IF sentence and validate NULL values in Xquery?

‏2012-09-02T16:41:03Z |
Hi everyone
I have the following function

declare function xf:getIbmdb2($bodyRequest as element()) as element(*) {
+ +
+ <ibmdb2 >+
+ <params>+
+ <string>1</string>+
</params>
<filters>
+ +
+ <filter>+
+ <property>code1</property>"+
+ + "<operator>eq</operator><value>{data($bodyRequest/ns0:code1)}</value>+
+ </filter>+
+ +
+ <filter>+
+ <property>code2</property>"+
+ + "<operator>eq</operator><value>{data($bodyRequest/ns0:code2)}</value>+
+ </filter>+
+ +
+ <filter>+
+ <property>code3</property>"+
+ + "<operator>eq</operator><value>{data($bodyRequest/ns0:code3)}</value>+
+ </filter>+
+ +
+ <filter>+
+ <property>code4</property>"+
+ + "<operator>eq</operator><value>{data($bodyRequest/ns0:code4)}</value>+
+ </filter>+
+ +
+ +
+ +
+ +
+ </filters>+
+ </ibmdb2>+

};
declare variable $bodyRequest as element() external;
I have the following questions

1.-How to use IF sentence in a Xquery function?
2.-How to validate NULL vales in a Xquery function?
For example...
IF ($ bodyRequest/ns0: code1)! = NULL {
<filter>
<property> code1 </ property> "
+ "<operator> Eq </ operator> <value> {data ($ bodyRequest/ns0: code1)} </ value>
</ filter>
Else {}}
Updated on 2012-09-02T16:48:30Z at 2012-09-02T16:48:30Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    746 Posts
    ACCEPTED ANSWER

    Re: How to use IF sentence and validate NULL values in Xquery?

    ‏2012-09-02T16:48:30Z  in response to chromosome
    Sorry, I have no idea what you are asking, perhaps because your question is badly formatted. IIRC the convention on this forum is to put

    { c o d e }

    before and after your code fragment (without the spaces of course)

    The syntax for an if expression in XQuery is

    if ( expression ) then expression else expression

    There is no such thing as a NULL value in XQuery - perhaps this is your problem - you need to understand the data model.