日期:2014-05-17 浏览次数:20594 次
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'fn_subword') BEGIN DROP FUNCTION fn_subword END GO CREATE FUNCTION fn_subword(@memo VARCHAR(1000)) RETURNS VARCHAR(1000) AS BEGIN DECLARE @REVERSE VARCHAR(1000)= REVERSE(@memo) DECLARE @Submemo VARCHAR(1000) SET @Submemo = SUBSTRING(@REVERSE,CHARINDEX('.',@REVERSE) + 1,CHARINDEX('_',@REVERSE) - CHARINDEX('.',@REVERSE) - 1) IF ISDATE(REVERSE(@Submemo)) = 1 BEGIN SET @REVERSE = REPLACE(@REVERSE,@Submemo + '_','') SET @Submemo = SUBSTRING(@REVERSE,CHARINDEX('.',@REVERSE) + 1,CHARINDEX('_',@REVERSE) - CHARINDEX('.',@REVERSE) - 1) END RETURN REVERSE(@Submemo) END GO DECLARE @Str VARCHAR(1000) = 'G0858号_中华人民共和国_中央人民政府(2009)16号_对外贸易会签联系单_2009-5-27.pdf' SELECT dbo.fn_subword(@Str)