Skip to main content

Using a Dynamic SQL Query

In fact, we're going to use a different type of query. Rather than a query, such as TopFilms, that is predefined in the class definition...

 <csp:query name=FilmList classname="Cinema.Film" queryname="TopFilms">

... we're going to use a dynamic query that is defined via SQL. We can do this with a <script> tag that specifies language="sql" and that encloses the actual SQL SELECT request.

The query shown here includes the same columns as TopFilms, but it displays all films and it sorts them by title, rather than by number of tickets sold.

<script language="sql" name=FilmList>
    SELECT ID, Description, Length, Rating, Title, Category->CategoryName
    FROM Cinema.Film
    WHERE PlayingNow = 1
    ORDER BY Title
FeedbackOpens in a new tab