May 24, 2011 at 3:21 pm
Hi!
i have two question. First, i use views for showing datas(tables) that don't made changes on it. For example, i show new products on a page. i use view for this. is it true?
Second, when i use views adding parameter. for example i want to list products that has categroyid=2.
can i pass categoryid as parameter to view.
Thankss..
May 24, 2011 at 3:42 pm
You can't create a view with a parameter.
Create a Stored Procedure.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
May 24, 2011 at 4:01 pm
I would prefer an inline-Table valued function over of a stored procedure.
The benefit: you can still use it like a view (e.g. SELECT * FROM your_function(param1))
May 24, 2011 at 4:18 pm
LutzM (5/24/2011)
I would prefer an inline-Table valued function over of a stored procedure.The benefit: you can still use it like a view (e.g. SELECT * FROM your_function(param1))
Agreed on the iTVF...some people even refer to them as "parameterized views".
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
May 25, 2011 at 2:25 pm
You don't need to use a view to see data that you're not currently trying to modify. You can just select from the table:
create table product (
id int identity(1,1) not null,
name varchar(255) not null,
categoryid int not null,
price money not null
)
select name, price, categoryid from product
If you want to restrict to just one category you can do this:
select name, price, categoryid from product
where categoryid = 2
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply