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 |
|
ramon6969
Starting Member
11 Posts |
Posted - 2009-12-17 : 11:48:31
|
| hi guys how do i do this SQL statements when a user typed in search text field in my ASP.net webpage? How do I 'chop' the typed-in phrases?examples:1. typed in phrase: marketing assistant jobsthe resulting SQL statement should be:SELECT field1,field2FROM myTableWHERE CONTAINS(*, 'marketing AND assistant AND jobs')2. typed in phrase: public administrationthe resulting SQL would be:SELECT field1,field2FROM myTableWHERE CONTAINS(*, 'public AND administration')3. typed in phrase: SQL server full text searchresult would be:SELECT field1,field2FROM myTableWHERE CONTAINS(*, 'SQL AND server AND full AND text AND search')thanks for any ideas.. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-17 : 12:18:36
|
Here's one way...replace the space with a dummy char..and then replace it with ' AND 'declare @d varchar(500) select @d = 'marketing assistant jobs'select @d = replace(replace(@d,' ',char(10)),char(10),' AND ')select @d |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-18 : 00:59:56
|
| ordeclare @d varchar(500) select @d = 'marketing assistant jobs'select @d = replace(@d,' ',' AND ')select @dMadhivananFailing to plan is Planning to fail |
 |
|
|
ramon6969
Starting Member
11 Posts |
Posted - 2009-12-18 : 06:10:36
|
| hi guys, thanks for your ideas. i tried all sorts to somehow incorporate your codes to this code:SELECT field1,field2FROM myTableWHERE CONTAINS(*, 'SQL AND server AND full AND text AND search')and i can not make it wor work when adapting your codes. how do i do that? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-18 : 07:04:44
|
| How are you passing the value?MadhivananFailing to plan is Planning to fail |
 |
|
|
ramon6969
Starting Member
11 Posts |
Posted - 2009-12-22 : 06:27:50
|
| Hi madhivanan, thanks.It seems to be doing it except when I tried to input phrases with OR and AND. It's giving errors.e.g.head and shoulderfather and sonchicken or eggexample:SELECT field1,field2FROM myTableWHERE CONTAINS(*, 'head AND and AND shoulder')I search the net but cant find any clue to resolve this. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-22 : 09:37:20
|
| try the method suggested @ 12/17/2009 : 12:18:36 |
 |
|
|
|
|
|
|
|