I am trying to execute below Sp_executesql with multiple parameters,but keep getting a syntax error
Must declare the table variable "@DBname".
SELECT @FileDateList = filedate files from TableA
SELECt @DataTimeField = DataTimeField from TableB
DECLARE @DBname Nvarchar(100)
SET @DBname = @DataBaseName + '.' + @TableName
SET @FileDateList = '''' + @FileDateList + ''''
SET @sql = N'SELECT DISTINCT filedate FROM @DBname
WHERE @DataSetTimeField IN (@FileDateList)'
SET @ParameterDefinition = N'
@DBname nvarchar(100),
@DataSetTimeField nvarchar(50),
@FileDateList as Nvarchar(1000) ';
EXECUTE sp_executesql @sql, @ParameterDefinition,
@DBname= @DBname , @DataSetTimeField=@DataSetTimeField, @FileDateList=@FileDateListI am not sure what i am doing wrong and how can i fix this error?