• Yes, you're right. I would absolutely do this as a stored procedure. If you post the CREATE TABLE and INSERT scripts for your Agents and ActiveCalls tables (maybe 2 records Agents, and 3 for ActiveCalls), someone can show you how to do it. (Actually, give it a try, and post your try...)  I have no problem helping you learn, but you gotta get your hands dirty and try it.

    You'd basically pass in all the values you intend to write to the table (except the value for @AgentID, because you don't know that yet).
    You'd use some code like I provided to get the AgentID with the fewest open calls, and assign it to a variable in your code. The other values you'd pass into the stored procedure.

    As I said, give it a bash, and post what you tried.  If you can't get it to work (and can't figure out the errors), post what you have and explain where it didn't work. Since you are reasonably new here, read Forum Etiquette: How to post data/code on a forum to get the best help - it explains a lot - and once you learn how to ask a good question, you'll get better and tested answers.

    Hope this helps!