I am writing a query that uses the CONTAINSTABLE function. For the third parameter in the CONTAINSTABLE call, I obtain the search term from a UDF. If I store the output of this UDF in a local variable and then pass the variable to the CONTAINSTABLE function, it works fine:
declare @temp nvarchar(255) = dbo.udf_GenerateTerm()
select * FROM ContainsTable([TableToSearch], Content, @temp, LANGUAGE 1033)
However, if I directly reference the UDF as a CONTAINSTABLE argument, I get a syntax error:
select * FROM ContainsTable([TableToSearch], Content, dbo.udf_GenerateTerm(), LANGUAGE 1033)
Is there any way around this, or this this a limitation of SQL Server?
Thanks.
This is a limitation of the SQL Server CONTAINSTABLE operation.
Here is the grammar for CONTAINSTABLE.
contains_search_condition is the part we are interested in. The grammar is defined thus
simple_term is made up of a word. A word is defined as
You can review the MSDN documentation on CONTAINS and CONTAINSTABLE for more info.