Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Text Search with blank spaces in SQL Server 2008

There is a problem occurs when I search data using full-text search with SQL Server 2008.

When I search data with no blank space it works but when I enter data with blank spaces it gives an error.

Like if I search 'amit' it works but if data is 'amit is working' it gives error.

I am using ASP.NET MVC 4.0 with SQL Server 2008.

Thanks Amit.

Create PROC [usp_Feedback_Search]
@Word nvarchar(500) ,   
@CompanyId UNIQUEIDENTIFIER     

As
IF ISNULL(@Word,'') = ''
 BEGIN
 Select          
  [Id] ,
[Content] ,    
[UserId],    
 [VoteCount] ,
 [IsOpen],
 [Deleted],
 [RowVersion],    
 [CreatedBy],     
 [CreatedOn],    
 [UpdatedOn],    
 [UpdatedBy],       
 [CompanyId], 
 [DisplayId],
  [Status]
 FROM Feedback         
  WHERE CompanyId=@CompanyId
  END
 ELSE
  BEGIN   

DECLARE @formatedWord varchar(500)='"'+@word+'\+"'

  Select          
  [Id] ,
[Content] ,    
[UserId],    
 [VoteCount],
 [IsOpen],
 [Deleted],
 [RowVersion],    
 [CreatedBy],     
 [CreatedOn],    
 [UpdatedOn],    
 [UpdatedBy],       
 [CompanyId], 
 [DisplayId],
  [Status]    
  FROM Feedback            
  Where CONTAINS(*,@Word)     
  and CompanyId=@CompanyId
  END
 GO
like image 387
Amit Sharma Avatar asked Nov 27 '22 09:11

Amit Sharma


1 Answers

I think Amit's answer may be unique to Amit. For everyone else...

wrap the value in double quotes:

SELECT ... WHERE Contains(tablename.columnname, '"amit is working"')

is the answer to

There is a problem occurs when I search data using full-text search with SQL Server 2008.

When I search data with no blank space it works but when I enter data with blank spaces it gives an error.

Like if I search 'amit' it works but if data is 'amit is working' it gives error.

like image 66
user1566694 Avatar answered Dec 15 '22 21:12

user1566694