50%记录的函数

ALTER FUNCTION [dbo].[fu_GetCaption](@Stage nvarchar(50)
,@T_stage_weeks int
,@S_stage_months int
,@RowNum int --第几行
)
RETURNS nvarchar(260)
AS
BEGIN
Declare @caption nvarchar(260)=''
SELECT @caption=caption
FROM(SELECT T_stage_weeks
,S_stage_months
,caption
,ROW_NUMBER()OVER(ORDER BY Id)rn
FROM XXX 
WHERE Stage = @Stage
AND T_stage_weeks = @T_stage_weeks
AND S_stage_months = @S_stage_months)t
WHERE t.rn % 2 = @RowNum % 2

return @caption
END

 

posted @ 2015-06-25 16:23  哈哈2222  阅读(181)  评论(0编辑  收藏  举报