Caché Server Pages QuickStart
Dynamic Query Example
[Home] [Back] [Next]
InterSystems: The power behind what matters   

Complete the following steps to use a dynamic query with CSP:

  1. Using Studio, create a new CSP page named MySamplePage2.CSP in csp/user.
  2. Add the following script to the page. The script defines a query that retrieves the PhoneNumberType and Number values for each PhoneNumber whose Contact value matches the input value. Note that the script retrieves the Contact value from %request. This technique is discussed later in the tutorial.
    <script language="sql" name="rs" p1="#($Get(%request.Data("ID",1)))#"
    SELECT PhoneNumberType, Number FROM CSPTutorial.PhoneNumber WHERE Contact = ?
  3. Add the following <csp:while> tag to the page after the above script. The tag iterates through the query's result set and displays the query results.
    <csp:while condition="rs.Next()">
    <p>#(rs.Data("PhoneNumberType"))# #(rs.Data("Number"))#</p>
  4. Finally, add the following form to MySamplePage2.CSP. The form contains a single text field and a Submit button. When the user presses the button, the value in the form field is submitted to the page. This becomes the search value used in the dynamic query.
    <p>Contact ID: <input type="text" size="5" name="ID"/></p>
    <input type="SUBMIT" Name="Search" Value="Search"/> 
  5. Open MySamplePage2.CSP in a Web browser. Enter a valid Contact ID value in the text field.
  6. Click the Search button. The page displays the phone numbers for the Contact with ID value 1.

Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA