简体   繁体   中英

Get matching names from SQL Server

My problem is, I have a database of people names and their achievements. Now, I have some paragraphs which contains the person names. I need to extract the names from those paragraphs. The web-end of the application will append a hyperlink of the extracted names with their activities.

Data in my database might look like:

Name          |  Achievement
----------------------------------------                              
Steve Jobs    |  Founder of Apple
Bill Gates    |  Founder of Microsoft

Now I have string like: After saving up some money, Steve Jobs took off for India in the search of enlightenment.

I need to find Steve Jobs from the above string and add to hyper link to that. Any idea how to do this?

You should save your data in some pre defined format for example, you can use *** at the start & end of person name like.

After saving up some money, ***Steve Jobs*** took off for India in the search of enlightenment.

Then you can extract the Person Names by finding *** through sql

EDIT:

I myself will try to find some other way to do it. For example i will save the Person Names in separate columns.

SQL Server really isn't the best place to do this, because a hyperlink is by definition HTML, but...

declare @s varchar(500) = 'After saving up some money, Steve Jobs took off for India in the search of enlightenment.'

select 
    @s = REPLACE(@s, name, '<a href="#">'+name+'</a>')    
from yourtable
where @s like '%'+name+'%'
select @s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM