If-statement and Loop-statements in stored procedures