Alex Rivera | Logout

Can we pass parameters to a view in SQL?

Asked 2009-11-06T12:30:56.437
181

Can we pass a parameter to a view in Microsoft SQL Server?

I tried to create view in the following way, but it doesn't work:

create or replace view v_emp(eno number) as select * from emp where emp_id=&eno;
Edit
Report

3 Answers

11

Why do you need a parameter in view? You might just use WHERE clause.

create view v_emp as select * from emp ;

and your query should do the job:

select * from v_emp where emp_id=&eno;
answered 2013-04-05T19:42:01.513
6

no. if you must then use a user defined function to which you can pass parameters into.

answered 2009-11-06T12:32:55.470
5

No, a view is queried no differently to SELECTing from a table.

To do what you want, use a table-valued user-defined function with one or more parameters

answered 2009-11-06T13:07:39.043

Your Answer