Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a Parameter
Message
From
12/07/1999 08:50:50
 
 
To
11/07/1999 01:27:16
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00232597
Message ID:
00240129
Views:
24
Jason,

SQL Server's views do not support any kind of parameterization like you can do in VFP. There are a couple of ways that you could simulate the same type of behavior:

First, you could create a stored procedure that accepted a parameter and returned a result set:

CREATE PROCEDURE foo
@p1 int
AS
SELECT * FROM table WHERE column1 = @p1

The second way would be to make a call to sp_executesql. sp_executesql provides a means to cache an ah-hoq query. When you call sp_executesql, you pass the parameters, their location in the query, types, and values. SQL Server uses this information to cache the query and make the query plan (the compiled version) reusable.

Third, you could create a view and pass the parameter in the query that access the view.

CREATE VIEW CAAuthors AS
SELECT * FROM authors WHERE state = 'CA'

When you query from the view, SQL Server will combine your query with the view.

SELECT * FROM CAAuthors WHERE au_fname LIKE 'A%'

Conceptually, the resultant query would look like this:

SELECT * FROM authors WHERE state = 'CA' and au_fname LIKE 'A%'

As you can see (hopefully I did a decent job) it's not necessary to make the view parameterized as long as you can supply the filter criteria in the query that accesses the view.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform