I have a SQL view, and I want to filter it using parameters passed to it. I was thinking about creating a stored procedure, however, after some research, I came to the conclusion that this is not possible.
Other similar threads suggested either creating a stored function or a stored procedure with the View's code embedded into it. My question is, what is the most efficient way to perform such task. My view is made up of around 70 lines of code, just for the record. What do you think? Below are some snippets that are taken from another thread.
The stored procedure would look like
CREATE PROCEDURE s_emp
(
@enoNumber INT
)
AS
SQL VIEW CODE +
WHERE
parameter=@stored_parameter
Or the user defined function would look like
CREATE FUNCTION u_emp
(
@enoNumber INT
)
RETURNS TABLE
AS
RETURN
(
SQL VIEW CODE +
WHERE
parameter=@stored_parameter
)
stored proceduretoSelectfrom the view with parameters in theWhereclause.viewfrom thestored procedure?Select * From View_NameTreat your view as a table. That's it. Add aWhereclause to narrow your selection down with parameters, etc. UseOrder byto sort. Everything you do with a table, do with your view.