Hi there,
Having big problems with a stored procedure I'm trying to write. It seems really simple but when I try to execute the procedure it throws an error.
Here is the proc:
USE [master]
GO
ALTER PROCEDURE [InsertTerm]
@TableName nvarchar(300),
@SearchTerm nvarchar(300)
AS
DECLARE @sql nvarchar(4000)
SELECT @sql = ' INSERT INTO [dbo].[tempdb].[@TableName]
SELECT [Col1] FROM [Table1] WHERE [Col1] = ' + @SearchTerm + ' OR [Col2] LIKE ' + '%' + @SearchTerm + '%' + ' OR [Col3] LIKE ' + '%' + @SearchTerm + '%'
EXEC sp_executesql @proc
GO
I've been playing with this now for best part of an hour and the errors seem to be coming from the @SearchTerm parameters.
Please Help...!
Many Thanks
View Complete Post