Reputation: 2208
I have a huge document with names and surnames, it currently looks like this:
"name1 surname1", "name2 surname2", "name3 surname3", "name4 surname4"....
In database in users
table there are columns name
surname
email
.
What I need now is to find emails of the people from the list.
I cannot separate names and surnames since there are dozens of them.
What is the best way to find them? I guess %like%
won't be working here. Please help me on this.
Note: What is difficult, some names and surnames are made of 3-4 words. This is not always only name and surname as 2 words.
Upvotes: 0
Views: 3484
Reputation: 629
DECLARE @mytxtvar TEXT;
SET @mytxtvar = LOAD_FILE('D:\\test.txt');
SELECT @mytxtvar;
SELECT email FROM user WHERE concat(name,' ',surname ) in @mytxtvar
Upvotes: 2
Reputation: 25
You can split each person on name and surname by using any language like JAVA, Then make a batch query job for all names using loop and save the result wherever you want. The query will be like this::
select email from user where name ='name1' and username ='surname1'
Upvotes: 0
Reputation: 1513
I don't get your problem.. isn't a simple query like this one enough?
select email
from user
where
(name = 'name1' and username = 'surname1') or
(name = 'name2' and username = 'surname2') or
...
You just need to split your initial list with some language that you like or even a simple text editor and then execute the query
Upvotes: 0