Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 sql query to find name in a field

Author  Topic 

kidroot
Starting Member

4 Posts

Posted - 2009-01-06 : 12:59:58
I am having great difficulty creating a query to return records from a table(s) where any value in the last name field in the employee table exists WITHIN ANY value within a field (full name) that contains peoples' full names in a different table. For example, my PERS2 table has a value in the last name called SMITH, but my other table would have the data as BLACKSMITH CONSTRUCTION COMPANY.

SELECT *
FROM PERS2, CONTRA
WHERE PERS2.LASTNAME In (CONTRA.FULLNAME);

Any assistance would be much appreciated!

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-01-06 : 13:01:59
Use the LIKE() function.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

kidroot
Starting Member

4 Posts

Posted - 2009-01-06 : 13:18:55
Thanks. I tried LIKE instead of IN but the query returned 0 records just like the IN query. From another query I previously ran, I know I have at least 61 instances where the last name exists somewhere in the full name field. I cannot figure out why the IN and/or LIKE queries will not return these 61 records at a minimum.

Any thoughts?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-06 : 13:20:18
WHERE CONTRA.FULLNAME LIKE '%' + PERS2.LASTNAME + '%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kidroot
Starting Member

4 Posts

Posted - 2009-01-06 : 14:16:47
THANKS! I was able to get a similar one to work by slightly adjusting the one you posted.

SELECT *
FROM PERS2, CONTRA
WHERE PERS2.LASTNAME Like '*'+CONTRA.FULLNAME+'*';

THANKS AGAIN!
I did notice though that I am unable to get this to work in a similar query that has Russian instead of English as the text. Any thoughts as to what would cause this?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-06 : 14:27:13
I just noticed you posted in the Access forum. My expertise is with Microsoft SQL Server, hence the % instead of * used in my last post. I don't have an answer as to your Russian/English question.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-01-06 : 14:51:08
What is the datatype and unicode compression setting of the column with the Russkie data?

"When a field's Unicode Compression property is set to Yes, any character whose first byte is 0 is compressed when it is stored and uncompressed when it is retrieved. Because the first byte of a Latin character— a character of a Western European language such as English, Spanish, or German— is 0, Unicode character representation does not affect how much storage space is required for compressed data that consists entirely of Latin characters."

You may need to convert your comparison string to unicode or something to get this to work.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

kidroot
Starting Member

4 Posts

Posted - 2009-01-06 : 17:17:51
Thank you! those are very helpful suggestions. The fields are "Text" and do not have Unicode compression. I copied the tables again and changed the Unicode compression and it did not affect the output of the query. This is very strange because other more "basic" queries appear to be executing properly against this non-English data.

I would love to hear any other suggestions if anyone has them.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-01-07 : 09:49:03
Try posting your question on an MS Access forum: http://www.dbforums.com/microsoft-access/

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page
   

- Advertisement -