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;
As already stated you can't.
A possible solution would be to implement a stored function, like:
CREATE FUNCTION v_emp (@pintEno INT)
RETURNS TABLE
AS
RETURN
SELECT * FROM emp WHERE emp_id=@pintEno;
This allows you to use it as a normal view, with:
SELECT * FROM v_emp(10)