Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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

I tried to create a 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;

1 Answer

0 votes
by (40.7k points)

You can implement the stored function, like this:

CREATE FUNCTION v_emp (@pintEno INT)

RETURNS TABLE

AS

RETURN

SELECT * FROM emp WHERE emp_id=@pintEno;

This will allow you to use it as the normal view, by using the below code:

SELECT * FROM v_emp(10)

To master SQL statements, queries and become proficient in SQL queries, enroll in an industry-recognized SQL Online Course.

Browse Categories

...