3
我的存儲過程:如何從EXEC sp_executeSql中選擇?
@currPage int,
@recodperpage int,
@name varchar(20) = NULL,
@type varchar(50) = NULL,
@size varchar(50) = NULL,
@country varchar(50) = NULL
AS
BEGIN
DECLARE @Sql NVARCHAR(MAX);
SELECT
@Sql = N'SELECT ROW_NUMBER()
OVER(ORDER BY MatchID Desc) AS RowNum,
MatchID,
NameMatch,
Images
FROM Match WHERE MatchID > 0 '
IF @type IS NOT NULL
SELECT @Sql += N' AND Type = ''' + REPLACE(convert(varchar(50),@type),'''','''''')+'''';
IF @size IS NOT NULL
SELECT @Sql += N' AND MatchSize = ''' + REPLACE(convert(varchar(50),@size),'''','''''')+'''';
IF @country IS NOT NULL
SELECT @Sql += N' AND Country = ''' + REPLACE(convert(varchar(50),@country),'''','''''')+''''
EXEC SP_EXECUTESQL @Sql
END
我想
select *
from EXEC SP_EXECUTESQL @Sql result
where RowNum between (@currPage - 1) * @recodperpage + 1
and @currPage * @recodperpage
http://stackoverflow.com/questions/35428540/insert-into-table-the-result-from-存儲過程加額外列/ 35429174#35429174 –