Exists() is a nice SQL construct. If checks for the existence of rows matching the WHERE clause. It does not actually return anything.

So the SELECT * is standard and acceptable in an EXISTS() function.

All those SET statements are simply boilerplate that I've copied from MS examples.

The GRANT is something you probably would not need - as we have permission issues that we have to deal with in our apps. You could remove the GRANT statement if you need to.

Now - let's get your SPROC written to insert into the MASTER and TRANS file.