Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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.4k points)

You can implement the stored function, like this:

CREATE FUNCTION v_emp (@pintEno INT)

RETURNS TABLE

AS

RETURN

SELECT * FROM emp WHERE [email protected];

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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...