SQL Server 2008 is telling me that it doesn't like the "+" in the CONTAINS. Not sure what I'm doing wrong here.
INSERT INTO dbo.tblImportTitles
(
ImportTitleGUID,
UserGUID,
TitleName,
TitleGUID
)
SELECT
ImportTitleGUID = T.Item.value('@ImportTitleGUID', 'uniqueidentifier'),
UserGUID = T.Item.value('@UserGUID', 'uniqueidentifier'),
TitleName = T.Item.value('@TitleName', 'varchar(255)'),
TitleGUID =
CASE
WHEN (SELECT TOP(2) COUNT(TitleGUID) FROM dbo.tblTitles WHERE CONTAINS(Title, '''' + T.Item.value('@TitleName', 'varchar(255)') + '''')) = 1
THEN (SELECT TitleGUID FROM dbo.tblTitles WHERE CONTAINS(Title,'''' + T.Item.value('@TitleName', 'varchar(255)') + ''''))
ELSE NULL
END
FROM @ImportTitlesInsertXml.nodes('BatchTitles/BTitle') AS T(Item)
Update
I'v decided to move this to a scalar function. It was a lot easier to handle the code that way.
use QUOTENAME(@VARIABLE,'''') the + is not your problem.