how can I pass the parameter to view in sql server.I have a stok which contain stok info including the quantity.I have a form and via this form I added the quatitiy to the stok . what I need is get the form value of quatitiy and add the the stok quantity which is available values.for this that I need the pass parameter to the view which automatically add this value to current value in the stok, thank you all for help
Asked
Active
Viewed 8,055 times
-2
-
Sorry, you cannot. See here: http://stackoverflow.com/questions/1687279/can-we-pass-parameter-to-a-view-in-sql – Alexander Jul 18 '13 at 09:16
-
Better then you will be use store procedure and pass parameter. It's also working like view select query. – Vikram Jain Jul 18 '13 at 09:18
-
Try to use `CONTEXT_INFO` – Devart Jul 18 '13 at 09:19
-
hmm possiable but what if I wanna use view – sakir Jul 18 '13 at 09:20
-
1devart can u clerify little bit – sakir Jul 18 '13 at 09:20
2 Answers
6
you can use a table function such as:
CREATE FUNCTION [dbo].[TblFunc_AAA]
(
@ID BIGINT
)
RETURNS TABLE
AS
RETURN
(
SELECT *
FROM MyTable
where aaa = @ID
)

asafrob
- 1,838
- 13
- 16
2
Actually views are only stored as SELECTs on a database, so you can't pass a parameter to it.
A stored procedure / function will fit right in. Declare one taking a parameter and only do a SELECT ... WHERE val = @paramval
CREATE PROCEDURE myproc
@in_quantity int
AS
SELECT * FROM tbl1
WHERE val = @in_quantity
GO;

makciook
- 1,537
- 10
- 19