• Did you check out this blog: http://www.sqlservercentral.com/blogs/discussionofsqlserver/2012/02/15/comparing-inline-and-multistatement-table-valued-functions/? According to BOL, an inline function is a single statement, if you need to create variables then it sounds like you might need a multistatement function. If that doesn't work for you, have you thought of trying out a Common Table Expression so you can "loop" through your data.