1

I'm implementing a command with full-text search on SQL Server and I'm having problems to build a dynamic query like this:

CONTAINS (MyTable, '@param1 AND @param2 AND NOT @param3')

So I found an alternative making a sequence of CONTAINS command, like this:

CONTAINS (MyTable, @param1) 
AND CONTAINS (MyTable, @param2) 
AND NOT CONTAINS (MyTable, @param1)

My question is: is it a problem to perform a SQL command with many CONTAINS command instead of only one like the first example?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
João Pedro
  • 429
  • 8
  • 20

1 Answers1

1

I am no SQL Server expert, but I would assume that SQL Server should be smart enough to compile it the way, it would have the best performance.

We are not talking about logical changes like Subquery vs Join which would compile in different way. The logic you have in the second example is exactly the same like you would have in the first. So youre fine to do your alternative.

If you want to pass the compile time, you should use a stored procedure. You can also obtain a Query Execution Plan to see if you have to much costs at this part of your Query.

Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111