去掉最后一个逗号,合并两个逗号为一个逗号

USE [SBCRM]
GO
/****** Object:  UserDefinedFunction [dbo].[F_SBCRM_LastChar]    Script Date: 10/19/2012 12:16:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:  <peter>
-- Create date: <2011-4-8>
-- Description: <去掉最后一个逗号,合并两个逗号为一个逗号>
-- =============================================
ALTER FUNCTION [dbo].[F_SBCRM_LastChar]
(
 -- Add the parameters for the function here
 @str nvarchar(max)
)
RETURNS nvarchar(max)
AS
BEGIN
 -- Declare the return variable here
 declare @str_return nvarchar(max)
 set @str_return='';
 if(right(@str,1)=',')
 begin
 set @str_return= substring(replace(@str,',,',','),1,len(replace(@str,',,',','))-1);
 end
 else
 begin
 set @str_return= @str;
 end
 return @str_return;
END

 

posted @ 2012-10-19 12:18  peterlee  阅读(159)  评论(0)    收藏  举报