Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

create a function to remove vowels from a given string Expand / Collapse
Author
Message
Posted Friday, February 15, 2013 10:13 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 3:51 PM
Points: 36,959, Visits: 31,469
Abu Dina (2/15/2013)
Jeff Moden (2/15/2013)
byecoliz (2/15/2013)
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


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.


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.


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.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1420658
Posted Friday, February 15, 2013 10:28 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, June 26, 2014 4:08 AM
Points: 708, Visits: 3,286
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.


See when people like you say stuff like this I get really worried!

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 middlename

But as you can see there are many combinations of this like

if 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 IFs

How else to implement this without IF or CASE ststements?!



Just realised this is so rude.. me hijacking the thread for my own needs. Sorry!

<lastnames match="equal">


<firstnames match="equal">
<middlenames match="equal">sure</middlenames>
<middlenames match="both_empty">sure</middlenames>
<middlenames match="one_empty">sure</middlenames>
<middlenames match="approx">likely</middlenames>
<middlenames match="contains">likely</middlenames>
<middlenames match="unequal">possible</middlenames>
</firstnames>
<firstnames match="sounds_equal">
<middlenames match="equal">sure</middlenames>
<middlenames match="both_empty">likely</middlenames>
<middlenames match="one_empty">likely</middlenames>
<middlenames match="approx">possible</middlenames>
<middlenames match="contains">possible</middlenames>
<middlenames match="unequal">zero</middlenames>
</firstnames>



---------------------------------------------------------


It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens

Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn
Post #1420669
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse