0

I am trying to parameterize some dynamic sql where the table name is what can change

SET @dynSQL = N'SELECT @Stu_Award_Year_Out = MAX(stu_award_year_token) FROM [PF].['+@Prefix + @DBNAME+'].[dbo].[stu_year]'

I can't figure out how to write the above statement so I can pass the variables in through the statement below

SET @ParamDefinition = N'
    @dbName NVARCHAR(10),
    @Prefix NVARCHAR(10),
    @Stu_Award_Year_OUT INT OUTPUT'

EXECUTE sys.sp_executesql
        @dynSQL,
        @ParamDefinition,
        @Prefix,
        @dbname,
        @stu_award_year_OUT = @stu_award_year_count OUTPUT 

Any help would be greatly appreciated!!!

Christine
  • 23
  • 5

0 Answers0