return a result from a dynamic tsql statement

I used the following tsql code to return a result from a dynamic sql statement:
declare @max_id as int=0
set @delta_sql  = ‘select @result = max(‘ + @first_column_name + ‘) from ‘ +@dest_full_table_name
EXECUTE sp_executesql @delta_sql  , N’@result int OUTPUT’ , @result=@max_id OUTPUT;

Leave a Reply

Your email address will not be published. Required fields are marked *