hi,
i am new to SQL. i have created a stored procedure which gets a input parameter "Category" and it selects datas which falls under this category. when i run this procedure it returns only the last row. it doesnt retreive the entire set of rows. which method should i follow to solve my problem.. i want all the rows which comes under the category to be returned ....
MY PROCEDURE
CREATE PROCEDURE [dbo].[Items_Category_sorted]
(
@.Category varchar(10),
@.ProductID Char(10) OUTPUT,
@.Name Char(50) OUTPUT,
@.UnitPrice Numeric(9) OUTPUT,
@.Stock Numeric(9) OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;
SELECT @.ProductID=ProductID,
@.Name=Name,
@.UnitPrice=UnitPrice,
@.Stock =Stock
From
ProductDetails
Where
Category=@.Category
END
As you're using output parameters, you can only have one value per parameter and this will be set to values in the last row returned by your query.
To return a recordset of multiple values, try:
CREATE PROCEDURE [dbo].[Items_Category_sorted]
(
@.Category varchar(10)
)
AS
BEGIN
SET NOCOUNT ON;
SELECT ProductID,
Name,
UnitPrice,
Stock
From
ProductDetails
Where
Category=@.Category
END
Hope this helps!
No comments:
Post a Comment