Can I create a One-Time-Use Function in a Script or Stored Procedure?

Solution 1:

You can create temp stored procedures like:

create procedure #mytemp as
begin
   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 ..

Solution 2:

You can call CREATE Function near the beginning of your script and DROP Function near the end.