• Just capture value of the RecordID that you just modified in the calling code, and pass it into the code to be dynamically executed:

    @query = 'DECLARE @RecordID AS Varchar(12)

    SET @RecordID = ''' + CAST(@RecordID_Updated AS varchar(10)) + '''

    SELECT t1.column1, t2.column1, t2.column2

    FROM Table AS t1

    INNER JOIN Table2 t2 on t1.RecordID = t2.T1RecordID

    WHERE t1.Record_ID = @RecordID'

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.