Abhishek Gupta
Abhishek Gupta

Reputation: 11

Multiple Parameters in Full Search Text?

I have created a full text catalog in SQL Server 2014. I want to use that catalog in a stored procedure.

DECLARE @FNAME VARCHAR(50) = '"ABHI"', @LNAME VARCHAR(50) ='GUPTA'

This query is working properly

SELECT * 
FROM Users 
WHERE CONTAINS(*,@FNAME)

My question is how can I pass multiple parameters to Contains, using an and condition between them?

Upvotes: 0

Views: 148

Answers (2)

Leif Neland
Leif Neland

Reputation: 1508

Until someone comes with the chrome-plated solution for having multiple terms in one CONTAINS, you can use two CONTAINS.

SELECT fie FROM foo WHERE CONTAINS(*,@fee) and CONTAINS(*,@fum)

Upvotes: 0

gofr1
gofr1

Reputation: 15977

You can concatenate this variables:

DECLARE @search nvarchar(4000),
        @FNAME VARCHAR(50) = 'ABHI', 
        @LNAME VARCHAR(50) = 'GUPTA'

SELECT @search = '"'+@FNAME+'" AND "'+@LNAME+'"'

SELECT * FROM Users WHERE CONTAINS(*,@search)

Upvotes: 1

Related Questions