[xquery-talk] if statements within where clauses?

pc.subscriptions pc.subscriptions at gmail.com
Wed Jun 14 21:28:34 PDT 2006


Just like Jonathan I am guessing a bit about the wanted semantics, but
perhaps something like

...

 

where contains($text, $keyword)

      and $var='all' or 

          (

         $entries//classcode = $region

     and $entries//classcode = $gender

     and $entries//classcode = $race

     and $entries/@type = $type

     )

 

is a possible (alternative) approach

 

Peter

 

-----Original Message-----
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf Of
Jonathan Robie
Sent: woensdag 14 juni 2006 20:19
To: Cindy Girard
Cc: talk at xquery.com
Subject: Re: [xquery-talk] if statements within where clauses?

 

Hi Cindy,

 

XQuery allows expressions to be combined very freely, and you can 

certainly use an if expression for conditional logic in a WHERE clause, 

as follows:

 

    ....

    where contains($text, $keyword)

      and if ($var ='all')

             $entries//classcode = $region

          else

             true()

 

I did not understand what you are trying to do well enough to know 

exactly what the query should look like.

 

Hope this helps!

 

Jonathan

 

-- 

Read my Blog: http://blogs.datadirect.com/jonathan_robie/

Learn XQuery:
http://media.datadirect.com/download/docs/ddxquery/tutorial_query.html

Learn XQJ (the JDBC for XQuery):
http://www.datadirect.com/developer/xquery/topics/xqj_tutorial/

Get DataDirect XQuery: http://www.datadirect.com/products/xquery/

 

 

 

Cindy Girard wrote:

> Hi.

> 

> I have the following piece of code:

> ----------------------

> $hits :=

>   for $entries in collection($collctn)//tei.2

>     let $docname := concat($entries/@id, '.xml')

>     let $divs := $entries//div1

>     let $text := $entries/text

>     where contains($text, $keyword)

>       and $entries//classcode = $region

>       and $entries//classcode = $gender

>       and $entries//classcode = $race

>       and $entries/@type = $type

>                                                    

>     return

>       <doc>{$entries/@type, <ct>-</ct>}</doc>,

> 

> ----------------------

> 

> and I need to make each 'and $entries...' statement conditional

> (if the variable doesn't equal 'all' then it needs to be included,

> otherwise, it needs to be left off).

> I believe I need to use a concat() to do it, but I can't seem to get

> the syntax right.

> 

> Should I put the entire hits variable into a concat()?

> 

> (if it matters, I'm using berkelydbxml for this)

> 

> Thanks,

> Cindy

> 

> Cindy Girard

> clm6u at virginia.edu

> 

>   

 

 

_______________________________________________

talk at xquery.com

http://xquery.com/mailman/listinfo/talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20060614/4334e782/attachment-0001.htm


More information about the talk mailing list