一个存储过程能同时有两个查询语句吗???
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME = 'PRO_NewsTrends')
DROP PROC PRO_NewsTrends
GO
CREATE PROC PRO_NewsTrends
@SubCategoryName NVARCHAR(20),
@Start int,
@end int
AS
WITH OrderedArticle AS
SELECT Title,Author,ArticleContent,AddTime,Article.SubCategoryId,
ROW_NUMBER() OVER(ORDER BY ArticleId DESC) AS rownumber
FROM Article,SubCategory
WHERE SubCategoryName = @SubCategoryName AND Article.SubCategoryId = SubCategory.SubCategoryId
SELECT ArticleId,Title,Author,ArticleContent,AddTime,SubCategoryId
FROM OrderedArticle
WHERE rownumber BETWEEN @Start AND @end
GO
这个好像有点问题,能帮忙找找错吗???
------解决方案--------------------lz的代码要改一下,如下:
WITH OrderedArticle AS (SELECT ROW_NUMBER() OVER(ORDER BY ArticleId DESC) AS rownumber,Title,Author...)
select ArticleId,Title,Author...from OrderedArticle WHERE rownumber BETWEEN @Start AND @end