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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Creating a search query

Author  Topic 

stenhoeve
Starting Member

5 Posts

Posted - 2014-05-08 : 15:33:19
Hello, I have a question how to create a search query. I have a database with text fields. I want to search for a specific word (string) that a users enters, but this word (string) must be searched after a specific word(string).

So for example if I have the text "I hope there is a specific answer for my question. Conclusion: This is a specific question." The word to be searched for is "specific" but it should be searched after the word "Conclusion:".

I hope it makes sense what I am trying to explain. Thank you.

Sten

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-08 : 15:48:04
I'm not 100% sure if this is what your after, but you could do a LIKE comparison:
DECLARE @Foo VARCHAR(MAX);
SET @Foo = 'I hope there is a specific answer for my question. Conclusion: This is a specific question.'

SELECT
1
WHERE
@Foo LIKE '%Conclusion:%specific%'
Go to Top of Page

stenhoeve
Starting Member

5 Posts

Posted - 2014-05-09 : 04:36:18
Thank you Lamprey, this worked perfectly
Go to Top of Page
   

- Advertisement -