An example of calling the stored procedure is provided
below. It can select the first 5 rows from the table called Products and order
them by the ProductName field after filtering for the product name that starts
with the letter A from the Northwind database. You can copy the code in
Listing 2 directly to an SQL Server Query analyzer.
Listing 2
Use Northwind
Exec DynamicSql 5,
'ProductName, SupplierID,QuantityPerUnit','Products','Order By ProductName','Where ProductName like ''A%'''
The following result is generated:
ProductName SupplierID QuantityPerUnit
Alice Mutton 7 20 - 1 kg tins
Aniseed Syrup 1 12 - 550 ml bottles
Another example with the usage of the output parameter is
presented below:
Exec DynamicSql 1,
'@ProdName = ProductName','Products',null,'Where ProductName like
''A%''','@ProdName', 'varchar'
This example would return the string "Alice
Mutton" to the calling part.