﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2012 / SQL Server 2012 -  T-SQL  / create a function to remove vowels from a given string / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 02:45:25 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>[quote]I've also found that if a function has over 200 IF statements, that it's time to go back to the drawing board.  Many such "hopeless" functions frequently do have a much more effective and easy to code solution.  there may also be the case where a stored procedure is more appropriate than a function.[/quote][strike]See when people like you say stuff like this I get really worried! :crying:The frunction is part of a record linkage application I'm developing. It joins a dataset on itself say on postcode and surname then individual elements of the duplicate pairs are compared and assigend scores for the name part, address, email etc...This particualr function calculates the likelyhood of two records having the same name details. See XML below. This is saying that IF Surname the same AND Firstname the same then the score will depend on the cmparison of middlenameBut as you can see there are many combinations of this likeif Surname the same AND forename sounds the same then middlename outcome gives different score.Now repeat this for when the surnames sounds the same and when surnames are approximately the same etc and this is how I ended up with so many IFsHow else to implement this without IF or CASE ststements?![/strike][b]Just realised this is so rude.. me hijacking the thread for my own needs. Sorry! [/b][code="xml"]&amp;lt;lastnames match="equal"&amp;gt;        &amp;lt;firstnames match="equal"&amp;gt;            &amp;lt;middlenames match="equal"&amp;gt;sure&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="both_empty"&amp;gt;sure&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="one_empty"&amp;gt;sure&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="approx"&amp;gt;likely&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="contains"&amp;gt;likely&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="unequal"&amp;gt;possible&amp;lt;/middlenames&amp;gt;        &amp;lt;/firstnames&amp;gt;        &amp;lt;firstnames match="sounds_equal"&amp;gt;            &amp;lt;middlenames match="equal"&amp;gt;sure&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="both_empty"&amp;gt;likely&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="one_empty"&amp;gt;likely&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="approx"&amp;gt;possible&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="contains"&amp;gt;possible&amp;lt;/middlenames&amp;gt;            &amp;lt;middlenames match="unequal"&amp;gt;zero&amp;lt;/middlenames&amp;gt;        &amp;lt;/firstnames&amp;gt;[/code]</description><pubDate>Fri, 15 Feb 2013 10:28:52 GMT</pubDate><dc:creator>Abu Dina</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>[quote][b]Abu Dina (2/15/2013)[/b][hr][quote][b]Jeff Moden (2/15/2013)[/b][hr][quote][b]byecoliz (2/15/2013)[/b][hr]thank you all for that new code. Abu Dina, you're right on the return correction. Now when i do that correction the function removes only the 'A' vowel., meaning the increment is not working.how can I organize these statements so that the increment works. thank[/quote]Forget the code that increments.  Do it the way that Lynn suggested.  It will be much faster than any scalar function that you can write.[/quote]Unless it's a SQL CLR C# UDF surely?Well I guess it depends on what the UDF needs to do. I recently posted a question about a SQL scalar function I had which contained over 200 IF statements. It was performing like a pig and I couldn't see a way of converting it to an iTVF so I write it in C#. The result? the C# version was 100 times faster than the SQL equivalent.[/quote]I agree... properly written CLRs are usually much better at string handling.   But they're not a panacea of performance and, speaking as a consultant, they're absolutely worthless if the shop you happen to be working in doesn't allow CLR. In this case (the vowel removal problem), you might find that the properly written iTVF function will be very nearly or just as performant as a CLR function.  I've also found that if a function has over 200 IF statements, that it's time to go back to the drawing board.  Many such "hopeless" functions frequently do have a much more effective and easy to code solution.  there may also be the case where a stored procedure is more appropriate than a function.</description><pubDate>Fri, 15 Feb 2013 10:13:02 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>Thank you all,I will take your advice.regards</description><pubDate>Fri, 15 Feb 2013 10:08:02 GMT</pubDate><dc:creator>byecoliz</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>[quote][b]Jeff Moden (2/15/2013)[/b][hr][quote][b]byecoliz (2/15/2013)[/b][hr]thank you all for that new code. Abu Dina, you're right on the return correction. Now when i do that correction the function removes only the 'A' vowel., meaning the increment is not working.how can I organize these statements so that the increment works. thank[/quote]Forget the code that increments.  Do it the way that Lynn suggested.  It will be much faster than any scalar function that you can write.[/quote]Unless it's a SQL CLR C# UDF surely?Well I guess it depends on what the UDF needs to do. I recently posted a question about a SQL scalar function I had which contained over 200 IF statements. It was performing like a pig and I couldn't see a way of converting it to an iTVF so I write it in C#. The result? the C# version was 100 times faster than the SQL equivalent.</description><pubDate>Fri, 15 Feb 2013 10:01:02 GMT</pubDate><dc:creator>Abu Dina</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>Take the others' advice and ditch the loop for the inline table valued function.</description><pubDate>Fri, 15 Feb 2013 09:57:54 GMT</pubDate><dc:creator>Abu Dina</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>and a simple cross apply example:[code]with myCTE(val)AS(SELECT 'Heavy rains that fell across the Upper Mississipp' UNION ALLSELECT 'i River Basin in the summer of 2007 were responsi' UNION ALLSELECT 'ble for the Federal Emergency Management Agency (' UNION ALLSELECT 'FEMA) 1771-DR-IL disaster declaration.  These sam' UNION ALLSELECT 'e rains caused significant flooding in southeaste' UNION ALLSELECT 'rn Minnesota, eastern Iowa, southern Wisconsin an' UNION ALLSELECT 'd northern Illinois.  Large portions of northern ' UNION ALLSELECT 'Illinois received between 125 and 175 inches of r' UNION ALLSELECT 'ain during this period, and this, combined ')select val,a.val2FROM MyCTECROSS APPLY (SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(val, 'A', ''), 'E', ''), 'O', ''), 'U', ''), 'I', '') as val2) a[/code]</description><pubDate>Fri, 15 Feb 2013 09:40:40 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>[quote][b]byecoliz (2/15/2013)[/b][hr]thank you all for that new code. Abu Dina, you're right on the return correction. Now when i do that correction the function removes only the 'A' vowel., meaning the increment is not working.how can I organize these statements so that the increment works. thank[/quote]Forget the code that increments.  Do it the way that Lynn suggested.  It will be much faster than any scalar function that you can write.</description><pubDate>Fri, 15 Feb 2013 09:37:29 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>thank you all for that new code. Abu Dina, you're right on the return correction. Now when i do that correction the function removes only the 'A' vowel., meaning the increment is not working.how can I organize these statements so that the increment works. thank</description><pubDate>Fri, 15 Feb 2013 09:35:29 GMT</pubDate><dc:creator>byecoliz</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>I'd do it this way and use it in a CROSS APPLY in the FROM clause:[code="sql"]create function dbo.RemoveVowels(    @pString varchar(max))returns tableasreturn (select replace(replace(replace(replace(replace(replace(@pString,'Y',''),'U',''),'O',''),'I',''),'E',''),'A','') NoVowels);go[/code]</description><pubDate>Fri, 15 Feb 2013 09:10:23 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>Arrghh David beat me to it! :-P[code="sql"]CREATE FUNCTION dbo.FN_REMOVEL_VOWELS (@STRING VARCHAR(max))returns varchar(max)as beginRETURN REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@STRING, 'A', ''), 'E', ''), 'O', ''), 'U', ''), 'I', '')ENDSELECT DBO.FN_REMOVEL_VOWELS('INFORMATION SYSTEM')[/code]Quick note about your original function. Don't [b]RETURN VARCHAR[/b] unless you know your string is never more than 8 characters long.</description><pubDate>Fri, 15 Feb 2013 09:06:10 GMT</pubDate><dc:creator>Abu Dina</dc:creator></item><item><title>RE: create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>doesn't this do it?[code="sql"]DECLARE @noVowels [varchar](50) SET @noVowels = 'Information System'SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@noVowels,'A',''),'E',''),'I',''),'O',''),'U','')[/code]</description><pubDate>Fri, 15 Feb 2013 09:04:06 GMT</pubDate><dc:creator>davidandrews13</dc:creator></item><item><title>create a function to remove vowels from a given string</title><link>http://www.sqlservercentral.com/Forums/Topic1420602-3077-1.aspx</link><description>Hi,I am creating a function to remove vowels from a given string but its not working,help me to correct it or give me the correct answer.thank you. CREATE FUNCTION FN_REMOVEL_VOWELS (@STRING VARCHAR(max))returns varcharas begindeclare @v varchar(max)='AEIOUY' ,@startpoint int =1,@letter varchar(max)select @letter=SUBSTRING(@v,@startpoint,1)while @startpoint&amp;lt;LEN(@v)begin select @STRING=REPLACE(@STRING,@letter,'')set @startpoint=@startpoint+1end return @STRINGendSELECT DBO.FN_REMOVEL_VOWELS('INFORMATION SYSTEM')</description><pubDate>Fri, 15 Feb 2013 08:57:59 GMT</pubDate><dc:creator>byecoliz</dc:creator></item></channel></rss>