I have a really simple problem:
Replace XX_FistName LastName (maybe dr. or phd anything trash) to firstname lastname
now i am using regexp replace:
trim(regexp_replace(lower(vhc.name),'xx_|dr|\.|\,|phd|jr','')
but this is really really slow...
can you give me some hint how can i replace this something faster? I have too much data to compare and do other functions on these data and it takes hours.
A reduced one.
trim(regexp_replace(lower(vhc.name),'xx_|[dj]r|[.,]|phd','')
Late response, but might help someone landing here just like me.
replace(table1.column_here, 'string_to_be_replaced', 'to_replace_with')
Related
Please help in understanding below regex.
Data:
396124436476092416,"Think about the life you livin but don't think so hard it hurts Life is truly a gift, but at the same it is a curse",Obey_Jony09
Regex for above data:
(",(?=([^\"]\"[^\"]\")[^\"]$)")
It is trying to group the nick wich made the quote, I guess.
I work for an organization that has a serious data quality problem with names. There are fifteen databases that contain information about people. For example:
Database 1
Name=Fre&d Blo-ggs DOB 01/01/1980
Database 2
Name=Freddy Bloggs DOB 01/01/1980
If a user searches for Fred Bloggs using my search tool then I want both records to be found. I was thinking about something like this:
SELECT * FROM Person WHERE Soundex('Fred Bloggs') = Soundex('Fre&d Blo-ggs')
Is it advisable to use Soundex like this rather than using replace statements like this:
select Replace(Replace(Replace(Name,',',''),'&',''),'#') from Person
where Replace(Replace(Replace(Name,',',''),'&',''),'#') = #Name
#Name is the variable passed in. Is there a better way of doing it e.g. using regular expressions? Does Soundex affect performance.
Nice idea. I would not suggest using it though. I suppose that "John Right" is not the same as "John Write", even though they hear the same. I mean that in the end, what it matters is what you want to compare.... If you want to compare if the name sounds are the same, then SOUNDEX is fine.
However, I would suggest correcting your data somehow. This would be a real solution, although I can imagine that is not an easy one.
Hope I helped!
If soundex is better than regex depends of your data. For example there are different soundex versions for different languages. You have to check with your data, which is better..
Of course soundex does affect performance as any other additional functions you are calling. If performance becomes a problem, I would advise to add an additional column with the already computed soundex or normalized names and to create an index over it.
From own experience I think a normalized / simplified search criterion as e.g. parts of surname, prename and month of birth date should be sufficient to get all persons, but not too many, so a user can decide which person (s)he really wants to choose.
Soundex wont help you. you will stuck if a consonant appears in the name by mistake.
Its better you go for string distance and specify a percentage. A kind of fuzzy matching.
Have a look at the below link for fuzzy matching using levenshtein edit distance algorithm.
Levenshtein edit distance - MS SQL SERVER
Hello this is my first post and I am fairly new to SQL. Really what I am trying to find is an equivilent to MID$ where I can make updates based on part of a field.
UPDATE OurTable
SET UpdateField='Text-2008-001-old'
WHERE '2008' like ('%' || UpdateField) AND KeyField='1'
In other words I wand to update to 'Text-2008-001-old' where the field might currently be 'Line-2008-000-000'
The position of the 2008 does not change within the existing data so really I just need to update and fields that contain 2008 where the KeyField is '1'
If there is a good online resource for SQL syntax that I have not found yet please feel free to point me there.
Hope I have explained this OK and thanks in advance for all suggestions.
I think you just need to use LIKE:
UPDATE OurTable
SET UpdateField='Text-2008-001-old'
WHERE UpdateField LIKE '%2008%' AND KeyField='1'
Or if there are always dashes around it, perhaps LIKE '%-2008-%' would be better.
Good luck.
UPDATE OurTable
SET UpdateField='Text-2008-001-old'
WHERE UpdateField like 'Line-2008%' AND KeyField='1'
There are a number of wildcards to use with the LIKE operator (%,_,[],[^], etc.) -- explained here: http://msdn.microsoft.com/en-us/library/ms179859.aspx.
There is also the substring() function -- explained here: http://msdn.microsoft.com/en-us/library/ms187748.aspx, that is kind of like a MID function in other languages. (WHERE...LIKE SUBSTRING(...))
I am trying to understand sql recursive statements, but it is really hard for me. For example:
Thats an exampe I am trying to understand and to write down the output.
Can sb pls explain me how this works, step by step?
greetings and thx in advance
maya
Also, see here - http://www.postgresql.org/docs/8.4/static/queries-with.html, where the steps of the recursive query evaluation are described.
The UNION ALL portion gets recursed until it returns no more records. I don't know if you can have multiple UNION ALL portions.
I am running the query below in Sybase application which works great but the consequences are when the first name is written like this, "ADNAN RAZA" it makes it "Adnan raza". Any function which I can use here to detect the position of letter after space or - and update. Can't do it manually there are more than 100k records.
update master set firstname =
upper(left(firstname,1))+lower(substr(firstname,2));
in Oracle SQL there is a function called initcap (character-expression).
Initcap returns character- expression with each word's first character in uppercase and the rest in lowercase.
i saw somewhere that in Sybase you have dbo.intcap(name) for this.
There is no solution for this at db level as it stands now.