SqlQuery Parameters Example

This example shows you how perform a select using query parameters. As you can see, query parameters can be named parameters and for each parameter in sql query, there is an equivalent in the params parameter. Some parameters also have their type specified, which is usually not necessary but required by some databases.

Smartsite SXML CopyCode image Copy Code
<se:sqlquery>
    <se:parameters>
        <se:parameter name="sql">
            select nr, title, modDate from vwActive where
                author = ?:author and
                moddate >= ?:thisyear and
                contenttype = ?:ct
        </se:parameter>
        <se:parameter name="params">
            <se:collection>
                <se:member name="author">John</se:member>
                <se:member name="thisyear" type="datetime">1/1/{datetime.getyear(datetime.now())}</se:member>
                <se:member name="ct" type="integer">{contenttype.getnumber('PWP')}</se:member>
            </se:collection>
        </se:parameter>
    </se:parameters>
</se:sqlquery>