Yes, composite indexes are not supported by the full-text index.
Can you post table DDL and sample data?
Also, consider using a subquery to restrict the set returned by one of the
tables, and then join the other table to the subquery result.
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Hi,
I added an extra ID field to the one-to-many table,
"tblShopItem_Category_Ref":
ID (PK, auto increment)
tblShopItem_ID
tblCategory_ID
- Then I created a view with this new key as the unique id:
CREATE VIEW viewAll WITH SCHEMABINDING AS
SELECT si.ID, si.tblShopProductType_ID, si.ItemName,
si.ShortDescription, si.Issue, si.Price, si.CampaignPrice,
si.CampaignStartDate, si.CampaignEndDate, scr.ID AS idxID, sc.ID AS
catID, sc.Category
FROM dbo.tblShopItem si
JOIN dbo.tblShopItem_Category_Ref scr ON scr.tblShopItem_ID = si.ID
JOIN dbo.tblShopCategory sc ON sc.ID = scr.tblShopCategory_ID
GO
CREATE UNIQUE CLUSTERED INDEX pk_viewAll ON viewAll (idxID)
- And the sproc was changed to this:
ALTER PROCEDURE [dbo].[usp_SearchAll] (
@PageIndex int,
@PageSize int,
@SearchString nvarchar(255) = NULL,
@CategoryID int = NULL
)
AS
SET NOCOUNT ON;
WITH SearchTable AS
(
SELECT ROW_NUMBER() OVER (ORDER BY va.ItemName) AS ROW,
va.ID, va.tblShopProductType_ID, va.ItemName, va.ShortDescription,
va.Issue, va.Price, va.CampaignPrice, va.CampaignStartDate,
va.CampaignEndDate, sir.Rating, dbo.GetCategories(va.id) AS Categories
FROM viewAll va
LEFT JOIN tblShopItemReview sir ON sir.tblShopItem_ID = va.ID
JOIN FREETEXTTABLE(viewAll, *, @SearchString) AS tblKey ON va.idxID
= tblKey.[KEY]
WHERE GetDate() BETWEEN va.StartDate AND va.EndDate
)
SELECT SearchTable.*, (SELECT MAX(ROW) FROM SearchTable) AS RC FROM
SearchTable
WHERE ROW BETWEEN (@PageIndex - 1) * @PageSize + 1 AND @PageIndex *
@PageSize
SET NOCOUNT OFF
- And it works very well! Becase I'm using ROW_NUMBER I still get
dublicate records - I figure if I didn't use ROW_NUMBER and added
DISTINCT to the SELECT I wouldn't! Also, I'd like to add the optional
search option for @CategoryID, like this:
AND va.catID = COALESCE(@CategoryID, va.catID)
- But because the JOIN with FREETEXTTABLE requires a @SearchString-
parameter, I can't leave that empty. Maybe it's better to put this in
it's own sproc?!
Best,
Mazzo
ML - 19 May 2008 10:22 GMT
> - And it works very well! Becase I'm using ROW_NUMBER I still get
> dublicate records - I figure if I didn't use ROW_NUMBER and added
> DISTINCT to the SELECT I wouldn't!
Consider eliminating duplicates without using DISTINCT, but rather by
properly restricting the result set (e.g. using the WHERE clause).
> Also, I'd like to add the optional search option for @CategoryID...
I can't see why you couldn't add that restriction.
> - But because the JOIN with FREETEXTTABLE requires a @SearchString-
> parameter, I can't leave that empty. Maybe it's better to put this in
> it's own sproc?!
Assuming you want to return all rows if @SearchString is null:
if @SearchString is null
begin
-- select without freetexttable
end
else
begin
-- select with freetexttable
end
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
nospam@please.net - 19 May 2008 11:05 GMT
Ah, of course - sometimes the solution is so simple you miss it!
Thanks so much for your reply.