Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SP_executesql Syntax error

$
0
0

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=@FileDateList

I am not sure what i am doing wrong and how can i fix this error?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>