Just to be clear, Chris was trying to get the OP to teach themselves how to answer such simple questions on their own instead of making them permanently dependent on the kindness of others on the web. Books Online is a very good tool for learning such basics and more. I'm amazed at how many people that are using SQL Server that don't even know what Books Online is.
Two questions for you now that you have the coded answer to your question... 1) Do you understand all of the parts of that code and why it works and 2) do you know what Books Online actually is?
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs