Hello -
I am attempting to use containstable based on a field passed into my stored proc. I know that I can use dynamic SQL to get the containstable to fire, but I heard that this is bad because SQL Server doesn't get to create an execution plan, so in turn I don't want to create dynamic sql.
here's how my code looks:
CREATE PROCEDURE sp_searchFullText
(
@userQuery nvarchar(500)
)
AS
SET NOCOUNT ON
create table #Results
(
pkey int,
ranking int
)
--the following lines spit out errors.
--assume that @userQuery is only one word
INSERT #Results (pkey, ranking)
(SELECT [Key], Rank FROM CONTAINSTABLE products, [name], @newUserQuery))
INSERT #Results (pkey, ranking)
(SELECT [Key], Rank FROM CONTAINSTABLE(products,description, @newUserQuery))
/*I know that this works, but isn't there a way around it?:
DECLARE @newUserQuery NVARCHAR(1024)
set @newUserQuery = 'SELECT [Key], Rank FROM CONTAINSTABLE(aceb2c_product, *, ''' +@newUserQuery+ ''') ORDER BY rank DESC'
INSERT #Results (pkey, ranking) EXEC(@newUserQuery)
*/
DROP TABLE #Results
SET NOCOUNT OFF
thanks in advance
leo
I am attempting to use containstable based on a field passed into my stored proc. I know that I can use dynamic SQL to get the containstable to fire, but I heard that this is bad because SQL Server doesn't get to create an execution plan, so in turn I don't want to create dynamic sql.
here's how my code looks:
CREATE PROCEDURE sp_searchFullText
(
@userQuery nvarchar(500)
)
AS
SET NOCOUNT ON
create table #Results
(
pkey int,
ranking int
)
--the following lines spit out errors.
--assume that @userQuery is only one word
INSERT #Results (pkey, ranking)
(SELECT [Key], Rank FROM CONTAINSTABLE products, [name], @newUserQuery))
INSERT #Results (pkey, ranking)
(SELECT [Key], Rank FROM CONTAINSTABLE(products,description, @newUserQuery))
/*I know that this works, but isn't there a way around it?:
DECLARE @newUserQuery NVARCHAR(1024)
set @newUserQuery = 'SELECT [Key], Rank FROM CONTAINSTABLE(aceb2c_product, *, ''' +@newUserQuery+ ''') ORDER BY rank DESC'
INSERT #Results (pkey, ranking) EXEC(@newUserQuery)
*/
DROP TABLE #Results
SET NOCOUNT OFF
thanks in advance
leo