Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a problem using the sql server full text with parameter

Alter Procedure[dbo].[SelectFullName]
@fullname nvarchar(16)
As
Select*from [dbo][NamePersonTB]
Where CONTAINS (fullname,'"*@fullname*"')


What I have tried:

CONTAINS (fullname,'"*@fullname*"')
Posted
Updated 27-Feb-22 21:29pm
Comments
Andre Oosthuizen 26-Feb-22 2:29am    
What problem do you have?
Lazard Ali 26-Feb-22 10:33am    
An express of non-boolean type.... When I use
CONTAINS (fullname,'"*@fullname*"')

1 solution

You are searching for records which contain the string "@fullname". If you want to search for records which contain the value of the @fullname parameter, you need to concatenate it into the search term:
SQL
CREATE OR ALTER PROCEDURE dbo.SelectFullName
(
    @fullname nvarchar(16)
)
As
BEGIN
DECLARE @query nvarchar(20);
    
    SET NOCOUNT ON;
    SET @query = N'"*' + @fullname + N'*"';
    
    SELECT
       *
    FROM
        dbo.NamePersonTB
    WHERE
        CONTAINS (fullname, @query)
    ;
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900