Database Exchange > Using MS SQL Server 2000 as a Data Source > Using an SQL Statement as a Record Source

Using an SQL Statement as a Record Source

This example shows how to retrieve the information for employees whose first names start with “AN” from table Employees on the same Database Exchange object,

To use an SQL statement as a data source:

  1. Use the connection.
  2. Select SQL Statement as record source.
  3. In the SQL Statement text box, enter the following:

SELECT *FROM Employees WHERE FirstName LIKE ‘AN%

  1. Click Apply to produce the following results on the Database Exchange object:

You also can change Record Source at runtime to display different records. The following example shows how to change SQL statement at runtime.

To change SQL statements at runtime:

  1. Copy and paste the following function to your Cicode file.

FUNCTION UpdateRecordSource(STRING sRecordSource)
_ObjectSetProperty(ObjectByName("AN35"), " RecordSource1", sRecordSource);

  1. Create a memory string tag, SQL_RECORDSOURCE.
  2. Add a button to the graphics page and enter the following code in the Input text box,


  1. Add the tag SQL_RECORDSOURCE on the page with display and input.
  2. At runtime, enter the following value to tag SQL_RECORDSOURCE and then click the button.

SELECT * FROM Employees WHERE FirstName LIKE 'M%'

The result lists two employees whose first name starts with “M”, as shown here. Be aware that method Refresh is not required if the command type is not a stored procedure as the control will automatically refresh data internally.