• From BOL, the first few sentences for CREATE FUNCTION:

    Creates a user-defined function. This is a saved Transact-SQL or common language runtime (CLR) routine that returns a value. User-defined functions cannot be used to perform actions that modify the database state.

    The purpose of a function is to return a value. For a simplistic model of why DML isn't supported in functions, consider this: you run a query which includes a function call against a table

    SELECT *, myResult = dbo.fnDML(GETDATE(), dbo.fnGetWeather(GETDATE(), 'Reading, UK')) ...

    - what's it going to do, add a column to a table if today is wednesday and it's sunny? Worse still, you could drop or add columns or even tables according to values in your source table. Row by row, the schema could change.

    The structure of your db, which took months of careful design, is now all over the place.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden