i’m trying to concatenate several columns from a persistent table into one column of a table variable, so that i can run a contains(“foo” and “bar”) and get a result even if foo is not in the same column as bar.
however, it isn’t possible to create a unique index on a table variable, hence no fulltext index to run a contains.
is there a way to, dynamically, concatenate several columns and run a contains on them? here’s an example:
declare @t0 table
(
id uniqueidentifier not null,
search_text varchar(max)
)
declare @t1 table ( id uniqueidentifier )
insert into
@t0 (id, search_text)
select
id,
foo + bar
from
description_table
insert into
@t1
select
id
from
@t0
where
contains( search_text, '"c++*" AND "programming*"' )
You cannot use
CONTAINSon a table that has not been configured to use Full Text Indexing, and that cannot be applied to table variables.If you want to use CONTAINS (as opposed to the less flexible PATINDEX) you will need to base the whole query on a table with a FT index.