Can I create a One-Time-Use Function in a Script or Stored Procedure?
You can create temp stored procedures like:
create procedure #mytemp asbegin select getdate() into #mytemptable;end
in an SQL script, but not functions. You could have the proc store it's result in a temp table though, then use that information later in the script ..
You can call CREATE Function
near the beginning of your script and DROP Function
near the end.
Common Table Expressions let you define what are essentially views that last only within the scope of your select, insert, update and delete statements. Depending on what you need to do they can be terribly useful.