sql存储过程里top后面可以跟参数吗?
CREATEPROCEDUREdbo.procTopicListByBoardIdSelect@boardIdINT,@rowBeginINTASBEGINSELECTT...
CREATE PROCEDURE dbo.procTopicListByBoardIdSelect
@boardId INT,
@rowBegin INT
AS
BEGIN
SELECT TOP 20 *
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId AND topicId NOT IN ( SELECT TOP @rowBegin topicId
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId
ORDER BY publishTime DESC)
ORDER BY publishTime DESC
END
GO
TOP @rowBegin 。。。。会报错,怎么解决?根据@rowBegin传过来的参数查询top数据。
那怎么在java里调用? 展开
@boardId INT,
@rowBegin INT
AS
BEGIN
SELECT TOP 20 *
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId AND topicId NOT IN ( SELECT TOP @rowBegin topicId
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId
ORDER BY publishTime DESC)
ORDER BY publishTime DESC
END
GO
TOP @rowBegin 。。。。会报错,怎么解决?根据@rowBegin传过来的参数查询top数据。
那怎么在java里调用? 展开
3个回答
展开全部
直接跟参数的形式,从 SQL 2005 才开始支持。 SQL 2000 是不支持的。
如果一定要使用的话,只能用 EXEC(@SQL)的方式执行
如果一定要使用的话,只能用 EXEC(@SQL)的方式执行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dbo.procTopicListByBoardIdSelect
@boardId INT,
@rowBegin INT
AS
BEGIN
declare @strtmp varchar(1000)
set @strtmp='SELECT TOP 20 *
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId AND topicId NOT IN ( SELECT TOP '+ convert(varchar(100), @rowBegin) + ' topicId
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId
ORDER BY publishTime DESC)
ORDER BY publishTime DESC '
execute @strtmp
END
GO
@boardId INT,
@rowBegin INT
AS
BEGIN
declare @strtmp varchar(1000)
set @strtmp='SELECT TOP 20 *
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId AND topicId NOT IN ( SELECT TOP '+ convert(varchar(100), @rowBegin) + ' topicId
FROM dbo.TBL_TOPIC
WHERE boardId=@boardId
ORDER BY publishTime DESC)
ORDER BY publishTime DESC '
execute @strtmp
END
GO
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以,要用括号括起来
TOP (@rowBegin)
TOP (@rowBegin)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询