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.
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 | Windows2 | Office3 | 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.ThanksPeeyush |
|
pmotewar
Yak Posting Veteran
62 Posts |
Posted - 2009-05-19 : 04:58:30
|
create table Table1 ( id int , Description varchar(30)insert into table1select 1,'Windows' union all select 2 , 'Office' union allselect 3 , 'Visual Studio' select * from table1 where Description like '%in%'Pankaj |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-19 : 10:44:41
|
use a parameter and do it like thisselect * from table1 where Description like '%' + @param + '%' then pass various values for parameter |
|
|
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 | email102 | addressand I'm searching using myemailaddress@gmail.com it should return ID's 101, and 102 |
|
|
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 @dataSELECT 101, 'email' UNION ALLSELECT 102, 'address'DECLARE @search varchar(100)SELECT @search = 'myemailaddress@gmail.com'SELECT *FROM @dataWHERE @search LIKE '%' + keyword + '%'/*ID keyword ----------- ---------- 101 email102 address(2 row(s) affected)*/[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-05-20 : 06:37:14
|
Thanks khtan.This is what exactly what i was looking for. |
|
|
|
|
|
|
|