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 2005 Forums
 Transact-SQL (2005)
 Full Text Help

Author  Topic 

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-05-19 : 04:45:03
Hi,
I have a KeyWords table. I need to pull the ID's of the keywords for any pattern occuring in the keywords.
Say the contents in the table are:

------------------

1 | Windows
2 | Office
3 | Visual Studio

-----------------

If I search for "in" it shoulg give me 1, If I search for "ffic", it should give 2, and so on.

I'm trying with Contains, but so far no luck.

Any urgent help is appreciated.

Thanks
Peeyush

pmotewar
Yak Posting Veteran

62 Posts

Posted - 2009-05-19 : 04:58:30
create table Table1 ( id int , Description varchar(30)

insert into table1
select 1,'Windows' union all
select 2 , 'Office' union all
select 3 , 'Visual Studio'


select * from table1 where Description like '%in%'




Pankaj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 10:44:41
use a parameter and do it like this


select * from table1 where Description like '%' + @param + '%'

then pass various values for parameter
Go to Top of Page

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-05-20 : 00:21:37
I didnt put it in right words. :(

If the Keyword are:

101 | email
102 | address

and I'm searching using myemailaddress@gmail.com it should return ID's 101, and 102
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-20 : 00:36:10
[code]
DECLARE @data TABLE
(
ID int,
keyword varchar(10)
)

INSERT INTO @data
SELECT 101, 'email' UNION ALL
SELECT 102, 'address'

DECLARE @search varchar(100)

SELECT @search = 'myemailaddress@gmail.com'

SELECT *
FROM @data
WHERE @search LIKE '%' + keyword + '%'

/*
ID keyword
----------- ----------
101 email
102 address

(2 row(s) affected)
*/
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-05-20 : 06:37:14
Thanks khtan.
This is what exactly what i was looking for.
Go to Top of Page
   

- Advertisement -