split full arabic name into pieces(SQL) - sql

in SQL Server:
i want to split full name like (محمد محمد وائل أبو العز) which is arabic name thats name found in one column, and i want to put first name محمد in column name (FirstName) and second name محمد in column name (SecondName), and third name وائل in column name (ThirdName), and Fourth name أبو العزin column name (FourthName)
put note that fourth name contsist of tow pieces and this problem may found in first or second or third name
what's your openion in this case

when you execute the following statement
SELECT FirstArabicName,
PARSENAME(REPLACE(FirstArabicName,' ','.'),4) 'FName' ,
PARSENAME(REPLACE(FirstArabicName,' ','.'),3) 'SName' ,
PARSENAME(REPLACE(FirstArabicName,' ','.'),2) 'TName' ,
PARSENAME(REPLACE(FirstArabicName,' ','.'),1) 'Sur Name'
FROM gfodatabase2013.dbo.Students
it works well with names that have one word only, but
you still have a problem with names that have two words like "Abd AlRahman"
how we can solve this problem?

Related

Showing Values in which there is a Substring that starts with a letter in range 'A' to 'X' followed by 2 letter of which second one is 'A' in Oracle

I need to find all the FIRST_NAMES in the table that looks like - There is a substring of 3 letter in the name of which first letter is in range 'A' to 'X' and 3rd one is 'A'. Moreover, the substring should be like '[A-X]_A' and the Name should be like '%[A-X]_A%'. But however ORACLE is showing NO DATA FOUND . Whenever I try with '[]' ORACLE can't find any data. Can anyone give me the solution?
For more information: I am using HR SCHEMA in LIVESQL.oracle.com for the purpose.
You want a regular expression:
where regexp_like(col, '[A-X].A')

Get a Count of a Field Including Similar Entries MS Access

Hey all I'm trying to parse out any duplicates in an access database. I want the database to be usable for the access illiterate and therefore I am trying to set up queries that can be run without any understanding of the program.
My database is setup where there are occasionally special characters attached to the entries in the Name field. I am interested in checking for duplicate entries based of the fields field1 and name. How can I include the counts for entries with special characters with their non-special character counterparts? Is this possible in a single step or do I need to add a step where I clean the data first?
Currently my code (shown below) only returns counts for entries not including special characters.
SELECT
table.[field1],
table.[Name],
Count(table.[Name]) AS [CountOfName]
FROM
table
GROUP BY
table.[field1],
table.[Name]
HAVING
(((table.[Name]) Like "*") AND ((Count(table.[Name]))>1));
I have tried adding a leading space to the Like statement (Like " *"), but that returns zero results.
P.S. I have also tried the Replace statement to replace the special characters, but that did not work.
field1 ##
1234567
1234567
4567890
4567890
name ##
brian
brian
ted
ted‡
Results
field1
1234567
name
brian
countofname
2
GROUP BY works by placing rows into groups where values are the same. So, when you run your query on your data and it groups by field1 and name, you are saying "Put these records into groups where they share a common field1 and name value". If you want 4567890, ted and 4567890, ted† to show in the same group, and thus have a count of 2, both the field1 and name have to be the same.
If you only have one or two possible special characters on the end of the names, you could potentially use Replace() or Substring() to remove all the special chars from the end of the names, but remember you must also GROUP BY the new expression you create; you can't GROUP BY the original name field or you won't get your desired count. You could also create another column that contains a sanitized name, one without any special character on the end.
I don't have Access installed, but something like this should do it:
SELECT
table.[field1],
Replace(table.[Name], "†", "") AS Name,
Count(table.[Name]) AS [CountOfName]
FROM
table
GROUP BY
table.[field1],
Replace(table.[Name], "†", "")

Oracle RegExp For Counting Words Occuring After a Character

I want to identify the number of words occurring after a comma, in a full name field in Oracle database table.
The name field contains format of "LAST, FIRST MIDDLE"
Some names may have up to 4 to 5 names, such as "DOE, JOHN A B"
For example, if the Name field = 'WILLIAMS JR, HANK' it would output 1 (for 1 word occurring after the comma.
If the Name field = 'DOE, JOHN A B' i want it to output 3.
I would like to use a regexp_count function to determine this count.
I am using the following code to identify how many words exist in the field and would like to modify it to include this functionality:
REGEXP_COUNT(REPLACE(fieldname, ',',', '), '[^]+')
It would likely have to remove the replace function in order to find the comma, but this was the best I could do so far.
Help is much appreciated!
How about the following:
REGEXP_COUNT( fieldname, "\\w", INSTR(fieldname, ",")+1)
I have updated the code as follows, which appears to be working as desired:
REGEXP_COUNT(fieldname, '[^ ]+', (INSTR(fieldname, ',')+1))

Select rows that has mixed charcters in a single value e.g. 'Joh?n' in name column

In an oracle table:
1- a value in a VARCHAR column contains characters that are not letters.
Consider a scenarion where a name in 'last_name' column contains regular characters (A - Z, a - z) as well as characters that are not english letters (e.g. '.', '-', ' ','_', '>' or similar).
The challenge is to select the rows that has names in 'last_name' as '.John' or 'John.' or '-John' or 'Joh-n'
2- Is it possible to have non-date values in a Date defined column? If yes, how can such records be selected in an oracle query?
Thanks!
I believe this will do the trick:
SELECT * FROM mytable WHERE REGEXP_LIKE(last_name, '[^A-Za-z]');
As for your 2nd question, I am unsure. I would be glad if someone else could add on to what I have to answer your 2nd question. I have found this website thought that might be of help. http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html
It explains the DATE format.
If I properly understand your goal, you need to select rows with last_name column containing the name 'John', but it may also have additional characters before, after, or even inside the name. In that case, this should be helpful:
select * from tab where regexp_replace(last_name, '[^A-Za-z]+', '') = 'John'

SQL - how to select words with certain values at the end of word

iam new to sql and i would like to know how can I find the letter or symbol at the end of value in column called Name?
E.g if i would find something i will write select * from 'table' where 'Name' like '%es%' but it will find me all rows contains es
Lets say - lesl, pespe, mess... but how to write select which will select just values with 'es' At the end of word? ... using regex i will use es\Z..... thanks in advance!
You have to remove the last %, so it will only select words ending with es.
select * from table where Name like '%es'
You're currently matching on: ..where 'Name' like '%es%'.
Which equates to anything, then 'es' then anything else.
Removing the last % changes the where to
anything then 'es'.
in short.. you need ..where 'Name' like '%es'
The query ..where 'Name' like '%es' will find columns where name ends with "ES".
But if we need to find column where name ends with either "E" or "S", the query would be
.. where 'Name' LIKE '%[ES]'
You can also use REGEX
select distinct city from station where city REGEXP '[aeiou]$';
Resources: To Know more about REGEXP
if you want to find name start with something like 'test'
use => select name from table where name like 'test%'.
if you want to find name end with something like 'test'
use => select name from table where name like '%test'.
if you want to find name start with s and end with h
use => select name from table where name like 's%'and name like '%h' or simply select name from table where name like 's%h'.
Try pattern [a-z]ed($) with regexp operator/function.
Pattern explanation:
[a-z] - match any letter
es - match es literally
($) - end of string (so make sure it's not followed by any letters)
Full query would be:
select * from test
where ingr regexp '[a-z]es($)'