What is wrong with my XQuery?

I just started learning about XQuery and am trying to play with it a little. Now, iv’e built what i think is a simple query and a correct one (a much as i can see) but SQL Manger prints me the error:
XQuery [query()]: “=” was expected.
I looked back at the code but i cant understand how to fix it… here is my code:

DECLARE @x AS XML = N'
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>';

SELECT @x.query('for $i in bookstore/book
    let $a := $i/author
    let $t := $i/title
    let $p := $i/price
    where $i/@price < 40
    return
    <This is a test>
    <author>$a</author>
    <title>$t</title>
    <price>$p</price>
    </This is a test>')
AS [I hope this works]

thanks in advance :slight_smile:

well for starters, tags cant be multiple words…

Do you mean <This is a test>. This could be the tag and the other words can be valueless attributes. They’re not, but technically they could be. So I don’t think that’s what tripping up this query.

Oh i doubt it is too, but this statement:

is only true of the opening tag. You don’t put attributes in the closing tag :wink: