title: Temporary Function for one-time script in SQL Server?
body: <p>In SQL Server 2008, I'm creating a script to convert a column to another type of column, and then replace the data with data from another table (We're using a new ID).
  I can do:  </p>
  
  <pre><code>ALTER TABLE @tablename
  ALTER COLUMN AccountID VARCHAR(30);
  
  UPDATE @tablename
  SET AccountID = SELECT AccountNumber
                    FROM OtherTable
                   WHERE AccountID = AccountID;
  </code></pre>
  
  <p>The only problem is that I have to run these same two commands for some 20-odd tables. Is there anyway to loop through these two, or write them as a temporary function/method/etc? I don't want to keep it, because we'll only need to do this once. Particularly, I'm having trouble creating a list of tables to loop through. I really want to find a better way than creating a function, running it on the tables, and then dropping it.</p>