From a38a8831703bb5b5e99853f9977b89a85fd22e39 Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 26 Mar 2012 13:30:55 +0000 Subject: [PATCH] Update User Defined Function vefn_FixSearchString to enable search for dash --- PROMS/DataLoader/PROMSFixes.Sql | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index 9ea198dd..15d8347a 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -596,3 +596,53 @@ begin order by OrdinalPath, contentid,auditid--actionwhen RETURN end +GO +/****** Object: UserDefinedFunction [dbo].[vefn_FixSearchString] Script Date: 03/26/2012 09:31:13 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +/* +select ID,ss,.dbo.vefn_FixSearchString(ss) +from ( +select 1 ID,'*' ss union +select 2 ID,'50%' ss union +select 3 ID,'IF*' ss union +select 4 ID,'*then:' ss union +select 5 ID,'530`F' ss union +select 6 ID,'check' ss union +select 7 ID,'RCP*Cooling' ss union +select 8 ID,'14%[34%]' ss union +select 9 ID,'\*' ss union +select 10 ID,'\?' ss union +select 11 ID,'_' ss union +select 12 ID,'[' ss union +select 13 ID,']' ss union +select 14 ID,'%' ss union +select 15 ID,'_' ss union +select 16 ID,'-' ss union +select 17 ID,'%' ss union +select 18 ID,'C* - *' ss +) tt order by ID +*/ +ALTER FUNCTION [dbo].[vefn_FixSearchString](@SearchString nvarchar(MAX)) +RETURNS nvarchar(MAX) +WITH EXECUTE AS OWNER +AS +BEGIN + -- This code adds % at the beginning and end if the beginning and end + -- of the search string if it does not have % at the beginning or end + Set @SearchString = replace(@SearchString,'[','[[]') + Set @SearchString = replace(@SearchString,'_','[_]') + Set @SearchString = replace(@SearchString,'%','[%]') + Set @SearchString = replace(@SearchString,'*','%') + Set @SearchString = replace(@SearchString,'?','_') + Set @SearchString = replace(@SearchString,'\%','*') + Set @SearchString = replace(@SearchString,'\_','?') + Set @SearchString = replace(@SearchString,'-','\u8209?') + IF(@SearchString like '[%]%') RETURN @SearchString + IF(@SearchString like '%[%]') RETURN @SearchString +RETURN '%' + @SearchString + '%' +END +GO