第一次用存储过程,在网上找了一个分页的存储过程,测试pass,
可是我要的功能的存储过程没找到,所以自己试着修改,由于存储过程语法不熟悉,也不知道错在哪?
/********************************** SP ***************************************/
CREATE Procedure get_PR_List@iPageCount int OUTPUT,  --总页数
@COMID uniqueidentifier, --公司ID
@PRID uniqueidentifier,  --产品ID
--@FeaturedProduct int,  --额外查询条件(问题一)
@iPageSize int           --页记录数as
set nocount on
begin
Select identity(int,1,1) as line,PR.*,CO.CO_Name,CO.CO_Icon into #T from Product PR join Countries CO on PR.PR_Country=CO.COID Where COMID=@COMID order by PR_CreateDate desc
--问题一:上面纸条语句如何添加额外条件(要从ASP输入检测某公司的特色产品FeaturedProduct)declare @iLine int
IF exists(SELECT line FROM #T where PRID=@PRID)
select @iLine=line from #T where PRID=@PRID--问题二:如何判断如果产品ID不存在于公司的产品库,ASP的代码如何获取改返回值declare @iPage int
IF @iLine%@iPageSize=0
SET @iPage=CEILING(@iLine/@iPageSize)
ELSE
SET @iPage=CEILING(@iLine/@iPageSize)+1--确定当前页记录页的始末记录
DECLARE @iStart int --start record
DECLARE @iEnd int --end record
SELECT @iStart = (@iPage - 1) * @iPageSize
SELECT @iEnd = @iStart + @iPageSize + 1--取当前页记录
select * from #T where line>@iStart and line<@iEnd--删除临时表
DROP TABLE #T--返回当前页
return @iPage
end
GO/********************************** ASP ***************************************/
Set MyComm = Server.CreateObject("ADODB.Command")
MyConStr = "......"
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "get_PR_List" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译

.Parameters.append .CreateParameter("@COMID",72,1,50,Session("COMID"))
.Parameters.append .CreateParameter("@PRID",72,1,50,ID)
'返回值(记录总量) 
.Parameters.Append .CreateParameter("RETURN",2,4)
'入参(每页记录数)
.Parameters.append .CreateParameter("@iPageSize",3,1,4,pagesize)

Set MyRst = .Execute  --网页提示在此行出错
end with