Showing posts with label specify. Show all posts
Showing posts with label specify. Show all posts

Monday, March 12, 2012

How to dynamic specify the colums in Full-Text Search?

My problem is simple: i want to dynamic specified the columns in the
ContainsTable, this is possible? Please see the example.
<Code>
Declare @.Test1 int
Declare @.Test2 int
Declare @.Query varchar(50)
Declare @.Temp varcahr(50)
--Test
Set @.Test1=1
Set @.Test1=0
Set @.Query='something'
--Add the columns to put in containstable
IF (@.Test1=1)
Begin
Set @.Temp='ID'
End
IF (@.Test2=1)
Begin
Set @.Temp= @.Temp + ',Name'
End
SELECT *
FROM
<table>
INNER JOIN
CONTAINSTABLE (<table>, @.Temp, @.Query) AS KEY_TBL
ON <table>.ID = KEY_TBL.[KEY]
</Code>
Thanks
you can only search on one column at a time, or if you are using contains or containstable, on all columns.
To get what you want you would have to do something like this
select * from tablename where contains(col1, 'test') or contains(col2, 'test') or contains(col3, 'test')
|||Renato,
Hilary is correct, you can only specify one column per CONTAINSTABLE
predicate or use the astrick "*" to indicate that you want to specify all
FT-enabled columns in the referenced table. However, this will be supported
in SQL Server 2005 (codename Yukon) with multi-column syntax, for example:
SELECT PrimaryKey, Col1, Col2
FROM FT_Table
WHERE CONTAINS( ( Col1, Col2 ) , ' "john" AND "kane" ')
Until the Yukon public beta becomes available, you will need to the astrick
to specificy all columns or use Hilary's example below. You might also find
the following stored proc useful as well:
use pubs
go
-- DROP PROCEDURE sp_FTSearchPubsInfo
go
CREATE PROCEDURE sp_FTSearchPubsInfo ( @.vcSearchText varchar(7800))
AS
declare @.s as varchar (8000)
set @.s='select pub_id, pr_info from pub_info where
contains(pr_info,'+''''+@.vcSearchText+''''+')'
exec (@.s)
go
EXEC sp_FTSearchPubsInfo '(("book" or "books") and ("publish" or
"publisher"))'
go
Regards,
John
"Hilary Cotter" <hilaryk@.att.net> wrote in message
news:61A1A4F7-557D-46CD-ADB4-9D36052924C1@.microsoft.com...
> you can only search on one column at a time, or if you are using contains
or containstable, on all columns.
> To get what you want you would have to do something like this
> select * from tablename where contains(col1, 'test') or contains(col2,
'test') or contains(col3, 'test')
|||Thanks for the help.
I will try the Hillary example...
See you later

How to dynamic specify the colums in Full-Text Search?

My problem is simple: i want to dynamic specified the columns in the ContainsTable, this is possible? Please see the example.


Declare @.Test1 int
Declare @.Test2 int
Declare @.Query varchar(50)
Declare @.Temp varcahr(50)

--Test
Set @.Test1=1
Set @.Test1=0
Set @.Query='something'

--Add the column to put in containstable
IF (@.Test1=1)
Begin
Set @.Temp='ID'
End

IF (@.Test2=1)
Begin
Set @.Temp= @.Temp + ',Name'
End

SELECT *
FROM
<table>
INNER JOIN
CONTAINSTABLE (<table>,@.Temp, @.Query) AS KEY_TBL
ON <table>.ID = KEY_TBL.[KEY]

ThanksOnly in Sql Server 2005 (Yukon) that is possible... :/