First we will create view and see the result and time taken by view. Then after we will create the function which returns table with a parameter.
Code
View
create view GetAllDatabyCountry as select product.productid,product.productname,product.code,product.productPrice ,country.countryname,city.cityname from product left outer join country on product.countryid=country.countryid left outer join city on product.cityId=city.cityId
Function
Create function GetDatabyCountryId(@countryId int) returns table as return ( select product.productid,product.productname,product.code,product.productPrice ,country.countryname,city.cityname from product left outer join country on product.countryid=country.countryid left outer join city on product.cityId=city.cityId where country.countryid=@countryId )
Using Function in Query
create procedure getDataByCountryId @countryId int as begin select getDataBycountry.* from dbo.GetDatabyCountryId(@countryId) as getDataBycountry end