简体   繁体   中英

Stored Procedure Parameter with FORMSOF and Thesaurus (SQL Server 2008 R2 SP2)

I have created a stored procedure

CREATE PROCEDURE [dbo].[GetTableColumns]
       @search_phrase varchar(100)
AS
BEGIN   
    SET NOCOUNT ON;

    SELECT * 
    from SearchTableColumn stc 
    where contains(*, 'FORMSOF(Thesaurus, @search_phrase)') 
    order by stc.weight desc
END

The stored procedure was created without any problems in SQL Server 2008 R2 SP2. If I execute the stored procedure in SQL Server Management Studio like this:

exec GetTableColumns 'instrument'

I got no records returned.

However, if I query the database with the following SQL,

SELECT * 
from SearchTableColumn stc 
where contains(*, 'FORMSOF(Thesaurus, instrument)') 
order by stc.weight desc

I got records returned.

So I am wondering if something I am missing in the stored procedure which prevents the records from being returned?

Thanks in advance.

You are searching for a literal 'FORMSOF(Thesaurus,@search_phrase)' in your table.

Try setting the search value using the passed in param:

CREATE PROCEDURE [dbo].[GetTableColumns]
@search_phrase varchar(100)
AS
BEGIN   
    SET NOCOUNT ON;

    Declare @search varchar(120) = 'FORMSOF(Thesaurus,' + @search_phrase + ')' 

    SELECT  * 
    from    SearchTableColumn stc 
    where   contains(*, @search) 
    order by stc.weight desc

END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM