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)
 Passing multiple words to full text search

Author  Topic 

John Sourcer
Yak Posting Veteran

91 Posts

Posted - 2008-11-04 : 01:51:43
My search

CONTAINSTABLE(Ranges, *, @Term) as A 


fails where @Term is multiple words, I know I have to encapsulate it but have forgotten how. :(

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-04 : 01:53:53
seems like you need dynamic sql
Go to Top of Page

John Sourcer
Yak Posting Veteran

91 Posts

Posted - 2008-11-04 : 01:58:56
Thanks visakh.

Query currently looks like this. So you're saying I have to build this up as a string and EXEC it as dynamic sql?


CREATE PROCEDURE [dbo].[SearchXXX]
@Term nvarchar(25),
@start int,
@limit int,
@sector int
AS
DECLARE @outerlimit int
BEGIN
SET @outerlimit = @start + @limit
SELECT DISTINCT * FROM (
SELECT Row_Number() OVER (ORDER BY ItemNo) AS RowID, count(*) over() as TotalCount, ia.ID, ItemNo, BagSize, Gauge, ra.SectorID, ra.Level1ID, ra.Level2ID, ra.Level3ID, ra.RangeDescription FROM Items ia INNER JOIN RangesItems ria ON ia.ID = ria.ItemID INNER JOIN Ranges ra ON ria.RangeID = ra.ID LEFT OUTER JOIN Level1Categories c1 ON ra.Level1ID = c1.ID LEFT OUTER JOIN Level2Categories c2 ON ra.Level2ID = c2.ID LEFT OUTER JOIN Level3Categories c3 ON ra.Level3ID = c3.ID WHERE ia.ID IN(
SELECT DISTINCT i.ID
FROM Items i,
CONTAINSTABLE(Items, *, @Term) as A
WHERE A.[KEY] = i.ID
UNION
SELECT DISTINCT ri.ItemID
FROM Ranges r INNER JOIN RangesItems ri ON r.ID = ri.RangeID,
CONTAINSTABLE(Ranges, *, @Term) as A
WHERE A.[KEY] = r.ID)) X WHERE (SectorID = @sector OR @sector = 0) AND RowID >= @start AND RowID <= @outerlimit
END
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-04 : 02:03:43
yup and since you need to use variables inside it use sp_executesql rather than EXEC()
Go to Top of Page

John Sourcer
Yak Posting Veteran

91 Posts

Posted - 2008-11-05 : 09:48:00
[code]SELECT DISTINCT * FROM (
SELECT Row_Number() OVER (ORDER BY ItemNo) AS RowID, count(*) over() as TotalCount, i.ID, ItemNo, ProductName, BagSize, Gauge, IsSectorHealth, IsSectorFood, IsSectorIndustrial FROM Items i, CONTAINSTABLE(Items, *, 'gusset bag') as A WHERE A.[KEY] = i.ID) X WHERE RowID >= 0 AND RowID <= 10 ORDER BY ItemNo[/code]

Syntax error near 'bag' in the full-text search condition 'gusset bag'.
Go to Top of Page

John Sourcer
Yak Posting Veteran

91 Posts

Posted - 2008-11-05 : 09:51:40
Apologies:

Term must be encapsulated '"gusset bags"'
Go to Top of Page
   

- Advertisement -