You should break up the select that sets the @newfilename and @cmd into two separate SET or SELECT. Set based queries do not go sequentiall, so the @newfilename that you set won't be available for use when you set @cmd if both are in the same statement.SELECT @NEWFILENAME = LEFT(@OldFileName,LEN(@OldFileName)-4) +'__'+ CONVERT(VARCHAR,CURRENT_TIMESTAMP,120)+'.TXT';SELECT @cmd = 'RENAME \\Adsnt4\d$\LAYER_1\FINAL_LAYER\' + @OldFileName + ' ' + @NewFileName