2011-08-11 10 views
-2

私はSQL Serverを初めて使用していて、現在学習しています。私は理解していないストアドプロシージャに従いました。ストアドプロシージャを単純なT-SQLに変換する

-- declare a new TABLE variable 
DECLARE @Products TABLE 
(RowNumber INT, 
ProductID INT, 
Name VARCHAR(50), 
Description VARCHAR(5000), 
Price MONEY, 
Image1FileName VARCHAR(50), 
Image2FileName VARCHAR(50), 
OnDepartmentPromotion bit, 
OnCatalogPromotion bit) 

-- populate the table variable with the complete list of products 
INSERT INTO @Products 
SELECT ROW_NUMBER() OVER (ORDER BY Product.ProductID), 
Product.ProductID, Name, 
SUBSTRING(Description, 1, @DescriptionLength) + '...' AS Description, Price, 
Image1FileName, Image2FileName, OnDepartmentPromotion, OnCatalogPromotion 
FROM Product INNER JOIN ProductCategory 
ON Product.ProductID = ProductCategory.ProductID 
WHERE ProductCategory.CategoryID = @CategoryID 
-- return the total number of products using an OUTPUT variable 
SELECT @HowManyProducts = COUNT(ProductID) FROM @Products 
-- extract the requested page of products 
SELECT ProductID, Name, Description, Price, Image1FileName, 
Image2FileName, OnDepartmentPromotion, OnCatalogPromotion 
FROM @Products 
WHERE RowNumber > (@PageNumber - 1) * @ProductsPerPage 
AND RowNumber <= @PageNumber * @ProductsPerPage 

してください!上記のストアドプロシージャを単純なt-sqlステートメントに変換して、これらのポイントを取得します。私は本当にあなたの仕事に感謝します。このような

+4

はこの宿題ですか?そうであれば、宿題としてタグ付けする必要があります。また、あなたがしようとしたことを示す必要があります。 – Taryn

+0

ポイント?何がポイント? –

+1

ここにあなたの仕事をする人はいません。特定の問題に関して助けが必要な場合は、質問を変更し、問題に多少の努力を加えたことをお知らせください。そうしないと、何の助けも得られないでしょう。 –

答えて

1

何かが働くだろう事前に

おかげで(私はそれをテストしていない):

--extract the requested page of products 
SELECT ProductID, Name, Description, Price, Image1FileName, 
Image2FileName, OnDepartmentPromotion, OnCatalogPromotion 
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY Product.ProductID) AS RowNumber, 
Product.ProductID, Name, 
SUBSTRING(Description, 1, @DescriptionLength) + '...' AS Description, Price, 
Image1FileName, Image2FileName, OnDepartmentPromotion, OnCatalogPromotion 
FROM Product INNER JOIN ProductCategory 
ON Product.ProductID = ProductCategory.ProductID 
WHERE ProductCategory.CategoryID = @CategoryID 
    ) A 
WHERE RowNumber > (@PageNumber - 1) * @ProductsPerPage 
AND RowNumber <= @PageNumber * @ProductsPerPage 

-- return the total number of products using an OUTPUT variable 
SELECT COUNT(ProductID) AS ProductCount FROM Product INNER JOIN ProductCategory 
ON Product.ProductID = ProductCategory.ProductID 
WHERE ProductCategory.CategoryID = @CategoryID 
関連する問題