The accepted answer isn't entirely correct. Enclosing the search term in double-quotes makes the grouping of words a "phrase" match. In this case, the ampsersand ( &
) can be treated as a literal character, such as when surrounded by one or more letters that do not form a known word. Just looking at your "AT&T"
example, we see:
DECLARE @Term NVARCHAR(100);
SET @Term = N'"AT&T"';
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 1);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 1);
GO
Returns:
keyword group phrase occurrence special display expansion source
id id term term type term
0x0061007400260074 1 0 1 Exact Match at&t 0 AT&T
As you can see, the ampersand presents no problem at all, as long as it is enclosed in double-quotes ( "
) which you are already doing, woo hoo!
However, that doesn't work as cleanly for the "Johnson & Johnson"
example:
DECLARE @Term NVARCHAR(100);
SET @Term = N'"Johnson & Johnson"';
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 1);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 1);
GO
Returns:
keyword group phrase occurrence special display expansion source
id id term term type term
0x006A006F0068006E0073006F006E 1 0 1 Exact Match johnson 0 Johnson & Johnson
0x006A006F0068006E0073006F006E 1 0 2 Exact Match johnson 0 Johnson & Johnson
That would seem to also match a search term of Johnson Johnson
, which isn't technically correct.
So, in addition to enclosing in double-quotes, you can also convert the ampersand to be an underscore ( _
) which is handled differently:
DECLARE @Term NVARCHAR(100);
SET @Term = N'"Johnson _ Johnson"';
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 1);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 1);
GO
Returns:
keyword group phrase occurrence special display expansion source
id id term term type term
0x006A006F0068006E0073006F006E 1 0 1 Exact Match johnson 0 Johnson _ Johnson
0x005F 1 0 2 Exact Match _ 0 Johnson _ Johnson
0x006A006F0068006E0073006F006E 1 0 3 Exact Match johnson 0 Johnson _ Johnson
AND, doing that one character translation does not seem to adversely affect the original "AT&T"
search:
DECLARE @Term NVARCHAR(100);
SET @Term = N'"AT_T"';
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, 0, 1);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 0);
SELECT * FROM sys.dm_fts_parser(@Term, 1033, NULL, 1);
Returns:
keyword group phrase occurrence special display expansion source
id id term term type term
0x00610074005F0074 1 0 1 Exact Match at_t 0 AT_T