title: SQL Server do declare statements in a loop cause significant speed issues and if so how can I resolve?
body: <p>I have a function which is called many times. The function has several DECLARE statements in the body of it.</p>
  
  <p>I'm wondering what the impact of this is if the function is called say, 100,000 times, and if there is a way to make the declaration global such that the same variable is re-used each time rather than being allocated/deallocated constantly.</p>
  
  <p>I might be thinking too much like a regular programmer in the way that SQL works, but ultimately I need to streamline it as much as possible to improve performance as currently it's shockingly bad.</p>