SqlServer_小工具_STUFF负Index支持

GO
CREATE FUNCTION ExtStuff(@str NVARCHAR(MAX),@start INT,@len INT,@rep NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @rts NVARCHAR(MAX);
    SELECT @rts=CASE WHEN @start>0 THEN STUFF(@str,@start,@len,@rep) WHEN @start<0 THEN REVERSE(STUFF(REVERSE(@str),-@start,@len,REVERSE(@rep))) ELSE NULL END;
    RETURN @rts;
END

例:
SELECT dbo.ExtStuff('123',3,1,'97')
//OUTPUT:
1297


SELECT dbo.ExtStuff('123',-1,1,'97')
//OUTPUT:
1297

 

 

posted on 2017-10-16 02:26  Thancoo  阅读(203)  评论(0编辑  收藏  举报

导航