Hi
I seem to get the following error when applying this method...
Syntax error converting the varchar value.. SPROC.. ..)to a column of data typ... doesn't actually tell me what datatype. Here is a copy of my sproc can you or anyone see where I could be going wrong?...
Code:
CREATE PROCEDURE dbo.Mysproc
@param1 INT = NULL,
@param2 INT = NULL,
@param3 INT = NULL,
@myColumn varchar(50)
AS
Declare @cmd nvarchar(4000)
SET @cmd = 'SELECT ' +@myColumn+ ' As FilterDDL
FROM myTable1 AS A
INNER JOIN myTable2 AS B ON B.an_ID = A.an_ID
INNER JOIN myTable3 AS C ON B.anotherID = C.anotherID
INNER JOIN myTable4 AS D ON B.yetanotherID = D.yetanotherID
WHERE D.yetanotherID = COALESCE('+@param1+', D.yetanotherID)
AND C.anotherID = COALESCE('+@param2+', C.anotherID)
AND B.an_ID = COALESCE('+@param3+', B.an_IDD)'
EXEC(@cmd)
GO
Many thanks in advance
Rit