Keyword search failing (long code, not urgent) | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Keyword search failing (long code, not urgent)

Hi all,<br /><br />Could anyone explain why the following code returns this error message??<br /><br />Thanks, Jaybee.<br /><br />Error: <br />Executed as user: LBH2000sqladmin. Execution of a full-text operation failed. A clause of the query contained only ignored words. [SQLSTATE 42000] (Error 7619). The step failed.<br /><br />Code:<br />———————————————————————————————–<br />– Class:Showhomes bespoke notification process<br />– Narrative:send E-mails relating to current notifications<br />– Owners:Notification<br />– History:16/05/2005 LP created<br />–20/07/2005 LP @MailURL modification<br />–20/06/2006 LP single quote error update<br />–07/07/2006 LP noise word and quote function<br />– Copyright: (C) Quicksilver 1986 – 2005 All rights reserved. <br />———————————————————————————————–<br /><br />CREATE PROCEDURE dbo.up_EmailProcess<br />@ProcessPeriod int = 0,<br />@MailOnly bit = 0,<br />@Remote bit = 0<br /><br />AS<br /><br />SET ANSI_DEFAULTS ON<br />SET NOCOUNT ON<br /><br />BEGIN<br />DECLARE @BaseURL varchar(100)<br />DECLARE @BaseSite varchar(100)<br />DECLARE @SubSite varchar(100)<br />DECLARE @Directory varchar(100)<br />DECLARE @PDFDirectory varchar(100)<br />DECLARE @MailURL varchar(100)<br /><br />DECLARE @LINKEDSERVER varchar(100)<br />DECLARE @TSQL varchar(2000)<br />DECLARE @OPENQUERY varchar(2000)<br />DECLARE @EXEC varchar(2000)<br /><br />DECLARE @iMsg int<br />DECLARE @hr int<br />DECLARE @source varchar(255)<br />DECLARE @description varchar(500)<br />DECLARE @output varchar(1000)<br /><br />DECLARE @ProcessDate smalldatetime<br />DECLARE @Process varchar(50)<br />DECLARE @ProcessCount int<br /><br />BEGIN TRANSACTION<br /><br />– Specificly update these details for new server implementation<br />SELECT @MailURL = ‘showplan.Homestead.gov.uk’, @BaseURL = ‘123.45.6.789’ — LBH<br />– SELECT @BaseURL = ‘LP-W2K3-‘Homestead’, @MailURL = ‘LP-W2K3-‘Homestead’– quicksand<br />SELECT @BaseSite = ”, @SubSite = ”, @Directory = ‘Public%20Docs’, @PDFDirectory = ‘Public%20PDF’, @ProcessDate = getdate(), @Process = ‘Email'<br /><br />–seperate SQL server use linked server local sets database name<br />SELECT @LINKEDSERVER = ‘sps-meetingdocs'<br /><br />INSERT INTO ProcessAudit VALUES(@ProcessDate, @Process,0,0,NULL)<br /><br />–seperate SQL server use linked server and OPENQUERY<br />IF @Remote = 0<br />BEGIN<br />SELECT @OPENQUERY = ‘INSERT INTO SearchResults SELECT UserID,[ID],SearchID,SearchKeywords, Escaped, Period, Expires, MeetingDate, DocumentType ,cast(DocumentTitle as varchar) as [DocumentTitle], Planning,Document,Extension,TimeCreated,CommitteeID,cast(Ward as varchar(8000)) as Ward, Item, NULL FROM [‘ + @LINKEDSERVER + ‘].dbo.'<br />END<br />ELSE<br />BEGIN<br />SELECT @OPENQUERY = ‘INSERT INTO SearchResults SELECT UserID,[ID],SearchID,SearchKeywords, Escaped, Period, Expires, MeetingDate, DocumentType ,cast(DocumentTitle as varchar) as [DocumentTitle], Planning,Document,Extension,TimeCreated,CommitteeID,cast(Ward as varchar(8000)) as Ward, Item, NULL FROM OPENQUERY'<br />END<br /><br />IF @MailOnly = 0<br />BEGIN<br />BEGIN TRANSACTION<br />EXEC up_UpdateDecisionMakers @MailOnly, @Remote, @BaseURL, @BaseSite, @SubSite, @LINKEDSERVER<br /><br />TRUNCATE TABLE SearchResults<br />COMMIT TRANSACTION<br />END<br /><br />DECLARE @CurrentUserID uniqueidentifier<br />DECLARE @CurrentEmail varchar(100)<br />DECLARE @CurrentUserTS timestamp<br />DECLARE @CurrentNotificationID uniqueidentifier<br />DECLARE @LastNotificationID uniqueidentifier<br />DECLARE @CurrentNotificationTS timestamp<br />DECLARE @Since smalldatetime<br />DECLARE @Keywords varchar(250)<br />DECLARE @Escaped bit<br />DECLARE @Period int<br />DECLARE @CommitteeID float<br />DECLARE @CurrentIdent int<br /><br />–mail detail<br />DECLARE @html1 varchar(8000)<br />DECLARE @html2 varchar(1000)<br />DECLARE @intro1 varchar(1000)<br />DECLARE @intro2 varchar(1000)<br />DECLARE @intro3 varchar(1000)<br />DECLARE @footer1 varchar(2000)<br />DECLARE @footer2 varchar(2000)<br /><br />DECLARE @Type VarChar(255) — MAPI Type<br />DECLARE @Recipients VarChar(255)– Semicolon-separated list <br />DECLARE @CC VarChar(255)– Semicolon-separated list <br />DECLARE @Subject VarChar(255)<br />DECLARE @From varchar(255)<br />DECLARE @Message varchar(8000)<br />DECLARE @Message2 varchar(8000)<br />DECLARE @ptr binary(16)<br />DECLARE @datalen int<br />DECLARE @notifyCount int<br /><br />DECLARE @Header VarChar(8000)<br />DECLARE @Contents VarChar(8000)<br />DECLARE @Contents2 VarChar(8000)DECLARE @ErrorMessage VarChar(255)<br /><br />DECLARE @SearchID int<br />DECLARE @ListName varchar(100)<br />DECLARE @SearchKeywords varchar(1000)<br />DECLARE @Expires smalldatetime<br />DECLARE @MeetingDate smalldatetime<br />DECLARE @DocumentType varchar(255)<br />DECLARE @Meeting varchar(8000)<br />DECLARE @DocumentTitle varchar(255)<br />DECLARE @PlanningApplicationNumber varchar(100)<br />DECLARE @Document varchar(255)<br /><br /><br />SELECT @html1 = ‘&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY ‘ + ‘Style="’ + ‘font-family: arial;font-size:12’ + ‘"’ + ‘&gt;’,<br />@html2 = ‘&lt;/BODY&gt;&lt;/HTML&gt;’,<br />@intro1 = ‘This email is sent to ‘,<br />@intro2 = ‘ and advises that content has been published on the Homestead website, which matches areas of interest you have registered according to the frequency you have requested i.e. weekly or monthly.&lt<img src=’/community/emoticons/emotion-4.gif’ alt=’;P’ />&gt;’,<br />@intro3 = ‘Follow the links below to access the documents:&lt<img src=’/community/emoticons/emotion-4.gif’ alt=’;P’ />&gt;’,<br />@footer1 = ‘You cannot change the parameters of these notification(s), but if required, you can delete and re-create them at any time time by ‘,<br />@footer2 = ‘&lt;BR&gt;&lt;BR&gt;This email is sent from an un-monitored mailbox: please do not reply to it.&lt;BR&gt;&lt;BR&gt;If you require any assistance relating to meeting documents, please email &lt;A href<a target="_blank" href=mailto:[email protected]&gt;[email protected]&lt;/A&gt;>mailto:[email protected]&gt;[email protected]&lt;/A&gt;</a>, or telephone 020 1111 1111 Monday to Friday between 9:00am and 5:00pm.'<br /><br />SELECT @type = NULL<br />SELECT @Recipients = ”<br />SELECT @From = ‘ [email protected]‘<br />SELECT @CC = ”<br />SELECT @Subject = ‘Homestead: Notification of content'<br />SELECT @Message = ”<br />SELECT @Message2 = ”<br /><br />IF @MailOnly = 0<br />BEGIN<br /><br />SELECT @Since = CASE @ProcessPeriod WHEN -1 THEN dateadd(hour,-1,getdate()) WHEN 0 THEN dateadd(week,-1,getdate()) ELSE dateadd(month,-1,getdate()) END<br /><br />– Get minimum value<br />SELECT @CurrentUserTS = MIN(US.[Timestamp])<br />FROM [User] US<br />WHERE CHARINDEX(‘@’,US.Email) &gt; 0 AND CHARINDEX(‘.’,US.Email) &gt; 0<br /><br />– Get first user<br />SELECT @CurrentUserID = UserID, @CurrentEmail = Email<br />FROM [User] US<br />WHERE [Timestamp] = @CurrentUserTS<br /><br />WHILE @CurrentUserID IS NOT NULL<br />BEGIN<br /><br />–get minimum notification<br />SELECT @CurrentNotificationTS = MIN(NF.[Timestamp])<br />FROM Notification NF<br />WHERE UserID = @CurrentUserID <br />AND ExpiryDate &gt;= getdate()<br />AND Period = @ProcessPeriod<br /><br />–get first notification<br />SELECT @CurrentNotificationID = NF.ID, @CommitteeID = CommitteeID, @Keywords = Keywords, @Escaped = Escaped, @Period = Period, @Expires = ExpiryDate<br />FROM Notification NF<br />WHERE NF.[Timestamp] = @CurrentNotificationTS<br /><br />– for each notification for this user do search<br />WHILE @CurrentNotificationID IS NOT NULL<br />BEGIN<br /><br />SELECT @Keywords = dbo.EscapedCharacter(@Keywords,’/’)<br />SELECT @Keywords = dbo.SPSCleanNoise(@Keywords) <br /><br />–seperate SQL server use linked server and OPENQUERY<br />IF @Remote = 0<br />BEGIN<br />SELECT @TSQL = ‘SearchResults(”’ + cast(@CurrentUserID as varchar(64)) + ”’,”’ + cast(@CurrentNotificationID as varchar(64)) + ”’,’ + char(39) + @BaseURL + char(39) + ‘,’ + char(39) + @BaseSite + char(39) + ‘,’ + char(39) + ‘ ‘ + char(39) + ‘,’ + char(39) + ‘Public Docs’ + char(39) + ‘,’ + char(39) + ‘Public Docs’ + char(39) + ‘,’ + char(39) + REPLACE(@keywords,char(39),char(39)+char(39)) + char(39) + ‘,’ + char(39) + cast(@CommitteeID as varchar) + char(39) + ‘,’ + char(39) + cast(@Escaped as varchar) + char(39) + ‘,’ + char(39) + cast(@Period as varchar) + char(39) + ‘,’ + char(39) + cast(@Expires as varchar) + ”” + ‘,’ + char(39) + cast(@Since as varchar) + ”” + ‘)’ <br />SELECT @CurrentNotificationID = NULL, @EXEC = @OPENQUERY + @TSQL<br />END<br />ELSE<br />BEGIN<br />SELECT @TSQL = ‘SELECT * FROM dbo.SearchResults(”’ + ”” + cast(@CurrentUserID as varchar(64)) + ”” + ”’,”’ + ”” + cast(@CurrentNotificationID as varchar(64)) + ”” + ”’,’ + char(39) + ”” + @BaseURL + ”” + char(39) + ‘,’ + char(39) + ”” + @BaseSite + ”” + char(39) + ‘,’ + char(39) + ”’ ”’ + char(39) + ‘,’ + char(39) + ”’Public Docs”’ + char(39) + ‘,’ + char(39) + ”’Public Docs”’ + char(39) + ‘,’ + char(39) + ”” + REPLACE(@keywords,char(39),char(39)+char(39)) + ”” + char(39) + ‘,’ + char(39) + ”” + cast(@CommitteeID as varchar) + ”” + char(39) + ‘,’ + char(39) + ”” + cast(@Escaped as varchar) + ”” + char(39) + ‘,’ + char(39) + ”” + cast(@Period as varchar) + ”” + char(39) + ‘,’ + char(39) + ”” + cast(@Expires as varchar) + ”” + ”” + ‘,’ + char(39) + ”” + cast(@Since as varchar) + ”” + ”” + ‘)’ <br />SELECT @CurrentNotificationID = NULL, @EXEC = @OPENQUERY + ‘([‘ + @LINKEDSERVER + ‘],’ + char(39) + @TSQL + char(39) + ‘)'<br />END<br /><br />EXEC(@EXEC)<br /><br />SELECT @CurrentNotificationTS = MIN(NF.[Timestamp])<br />FROM Notification NF<br />WHERE UserID = @CurrentUserID AND NF.[Timestamp] &gt; @CurrentNotificationTS<br />AND ExpiryDate &gt;= getdate()<br />AND Period = @ProcessPeriod<br /><br />–get next notification<br />SELECT @CurrentNotificationID = NF.ID, @CommitteeID = CommitteeID, @Keywords = Keywords, @Escaped = Escaped, @Period = Period, @Expires = ExpiryDate<br />FROM Notification NF<br />WHERE NF.[Timestamp] = @CurrentNotificationTS<br />END<br /><br />SELECT @CurrentUserTS = MIN(US.[Timestamp])<br />FROM [User] US<br />WHERE CHARINDEX(‘@’,US.Email) &gt; 0 AND CHARINDEX(‘.’,US.Email) &gt; 0 AND US.[Timestamp] &gt; @CurrentUserTS<br /><br />– Get next user<br />SELECT @CurrentUserID = NULL, @CurrentEmail = NULL<br />SELECT @CurrentUserID = UserID, @CurrentEmail = Email<br />FROM [User] US<br />WHERE [Timestamp] = @CurrentUserTS<br />END<br />END<br /><br />–mail only<br />CREATE TABLE #tempUser (<br />Ident int identity(1,1),<br />UserID uniqueidentifier,<br />Email varchar(100)<br />)<br /><br />CREATE TABLE #tempNotify (<br />[ID] uniqueidentifier NULL,<br />SearchID float NULL,<br />SearchKeywords varchar(400) NULL,<br />Escaped bit NULL,<br />Period int NULL,<br />Expires smalldatetime NULL,<br />[Timestamp] timestamp<br />)<br /><br />INSERT INTO #tempUser <br />SELECT DISTINCT SR.UserID, US.Email <br />FROM SearchResults SR<br />INNER JOIN [User] US<br />ON SR.UserID = US.UserID<br /><br />–audit<br />SELECT @ProcessCount = count(0) FROM #tempUser<br /><br />UPDATE ProcessAudit SET Estimated = @ProcessCount<br />WHERE ProcessDate = @ProcessDate AND Process = @Process<br /><br />SELECT @ProcessCount = 0<br /><br />–get first user<br />SELECT @CurrentUserID = UserID, @CurrentEmail = Email, @CurrentIdent = 1<br />FROM #tempUser<br />WHERE Ident = 1<br /><br />–for each user construct mail<br />WHILE @CurrentUserID IS NOT NULL<br />BEGIN<br /><br />TRUNCATE TABLE #tempNotify<br />SELECT @CurrentUserTS = NULL, @Message = @html1 + @intro1 + ISNULL(@CurrentEmail,’unknown’) + @intro2 + CHAR(9) + CHAR(13) + CHAR(9) + CHAR(13) + @intro3, @Header = ”, @Contents = ”, @Message2 = ”, @Contents2 = ”<br /><br />UPDATE [User] SET LastEmail = ” WHERE UserID = @CurrentUserID<br />SELECT @ptr = textptr([User].LastEmail) FROM [User] WHERE UserID = @CurrentUserID<br /><br />UPDATETEXT [User].LastEmail @ptr null 0 @Message<br /><br />–get documents for user<br />INSERT INTO #tempNotify SELECT DISTINCT <br />[ID],SearchID,SearchKeywords,Escaped, Period,Expires,NULL<br />FROM SearchResults<br />WHERE UserID = @CurrentUserID<br /><br />IF @@ROWCOUNT &gt; 0<br />BEGIN<br />SELECT @Contents = ‘&lt;TABLE ‘ + ‘Style="’ + ‘font-family: arial;font-size:12’ + ‘"’ + ‘&gt;&lt;TR ‘ + ‘Style="’ + ‘font-weight: bold’ + ‘"’ + ‘&gt;&lt;TD ‘ + ‘Width="’ + ‘200’ + ‘"’ + ‘&gt;Meeting Name&lt;/TD&gt;&lt;TD ‘ + ‘Width="’ + ‘100’ + ‘"’ + ‘&gt;Keyword(s)&lt;/TD&gt;&lt;TD ‘ + ‘Width="’ + ‘100’ + ‘"’ + ‘&gt;Expires&lt;/TD&gt;&lt;TD ‘ + ‘alighn:right;width="’ + ‘150’ + ‘"’ + ‘&gt;Link&lt;/TD&gt;&lt;/TR&gt;'<br />UPDATETEXT [User].LastEmail @ptr null 0 @Contents<br />ENDSELECT @CurrentUserTS = MIN([Timestamp])<br />FROM #tempNotify<br /><br />WHILE @CurrentUserTS IS NOT NULL<br />BEGIN<br />SELECT @CurrentNotificationID = [ID], @SearchID = cast(SearchID as int), @ListName = ISNULL(DML.ListName,”), @SearchKeywords = ISNULL(TN.SearchKeywords,”), @Escaped = TN.Escaped, @Period = TN.Period, @Expires = TN.Expires<br />FROM #tempNotify TN<br />LEFT JOIN DecisionMakersList DML ON cast(TN.SearchID as integer) = DML.ListID<br />WHERE TN.[Timestamp] = @CurrentUserTS<br /><br />SELECT @notifyCount = COUNT(Document)<br /&gt ;FROM SearchResults<br />WHERE [ID] = @CurrentNotificationID<br /><br />SELECT @Contents = ‘&lt;TR&gt;&lt;TD&gt;’ + CASE @ListName WHEN ” THEN ‘Not Specified’ ELSE @ListName END + ‘&lt;/TD&gt;&lt;TD&gt;’ + CASE @SearchKeywords WHEN ” THEN ‘Not Specified’ ELSE CASE @Escaped WHEN 0 THEN REPLACE(@SearchKeywords,char(39), char(34)) ELSE REPLACE(REPLACE(@SearchKeywords,char(39), char(34)),char(34),”) END END + ‘&lt;/TD&gt;&lt;TD&gt;’ + CONVERT(varchar,@Expires,106) + ‘&lt;/TD&gt;&lt;TD&gt;&lt;A HREF<a target="_blank" href=http://’>http://'</a> + @MailURL + CASE @BaseSite WHEN ” THEN ” ELSE ‘/’ + @BaseSite END + ‘/Shared%20Documents/Search_Since.aspx?_Committee=’ + cast(@SearchID as varchar) + ‘&_Keyword%28s%29=’ + CASE @Escaped WHEN 0 THEN REPLACE(REPLACE(@SearchKeywords,’ ‘, ‘%20′),char(39),’%22′) ELSE REPLACE(REPLACE(REPLACE(@SearchKeywords,’ ‘, ‘%20′),char(39),’%22’),char(34),char(34)) END + ‘&_Since=’ + CASE @Period WHEN 0 THEN REPLACE(CONVERT(varchar(11),dateadd(week,-1,getdate()),106),’ ‘, ‘%20′) ELSE REPLACE(CONVERT(varchar(11),dateadd(month,-1,getdate()),106),’ ‘, ‘%20’) END + ‘&gt;’ + cast(ISNULL(@notifyCount,0) as varchar) + ‘ document(s)&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;'<br />UPDATETEXT [User].LastEmail @ptr null 0 @Contents<br /><br />SELECT @CurrentUserTS = MIN([Timestamp])<br />FROM #tempNotify<br />WHERE [Timestamp] &gt; @CurrentUserTS<br />END<br /><br />SELECT @Contents2 = ‘&lt;/TABLE&gt;&lt;BR&gt;&lt;BR&gt;’ + @footer1 + ‘&lt;A HREF<a target="_blank" href=http://’>http://'</a> + @MailURL + CASE @BaseSite WHEN ” THEN ” ELSE ‘/’ + @BaseSite END + ‘/Shared%20Documents/Notify_Update.aspx?Action=Delete&User=’ + cast(@CurrentUserID as varchar(64)) + ‘&ID=’ + cast(@CurrentNotificationID as varchar(64)) + ‘&gt;clicking here.&lt;/A&gt;’ + @footer2 + @html2<br />UPDATETEXT [User].LastEmail @ptr null 0 @Contents2<br /><br />select @datalen = ISNULL(DATALENGTH(LastEmail),0) FROM [User] WHERE UserID = @CurrentUserID<br />IF @datalen &gt; 7999<br />BEGIN<br />SELECT @Message = SUBSTRING(LastEmail, 1, 7999) FROM [User] WHERE UserID = @CurrentUserID<br />SELECT @Message2 = SUBSTRING(LastEmail, 8000, @datalen – 7999) FROM [User] WHERE UserID = @CurrentUserID<br />END<br />BEGIN<br />SELECT @Message = SUBSTRING(LastEmail, 1, 7999) FROM [User] WHERE UserID = @CurrentUserID<br />END<br /><br />SELECT @Recipients = @CurrentEmail<br /><br />– SELECT ‘up_send_cdosysmail ‘ + ”” + @From + ”’,”’ + @Recipients + ”’,”’ + @Subject + ”’,”’ + @Message + @Message2 + ””<br /> EXEC(‘up_send_cdosysmail ‘ + ”” + @From + ”’,”’ + @Recipients + ”’,”’ + @Subject + ”’,”’ + @Message + @Message2 + ””)<br /><br />–get next user<br />SELECT @CurrentIdent = @CurrentIdent + 1, @CurrentUserID = NULL, @ProcessCount = @ProcessCount + 1<br /><br />UPDATE ProcessAudit SET Actual = @ProcessCount<br />WHERE ProcessDate = @ProcessDate AND Process = @Process<br /><br />SELECT @CurrentUserID = UserID, @CurrentEmail = Email<br />FROM #tempUser<br />WHERE Ident = @CurrentIdent<br />END<br /><br />UPDATE ProcessAudit SET ProcessFinished = getdate()<br />WHERE ProcessDate = @ProcessDate AND Process = @Process<br /><br />DROP TABLE #tempUser <br />DROP TABLE #tempNotify<br /><br />COMMIT TRANSACTION<br /><br />RETURN 0<br /><br />END<br />GO<br />
Check the following articles which may help you… http://www.databasejournal.com/features/mssql/article.php/3454281
http://dbforums.com/t968373.html
http://www.sqlservercentral.com/columnists/jwiner/20010422025723_1.asp
MohammedU.
Moderator
SQL-Server-Performance.com
]]>