title: tsql query with defensive measure to prevent filling up tempdb
body: <p>I recently wrote a query that, rather surprisingly, filled our tempdb. I was simply doing a string comparision on several thousand records, and I imagine because the strings where so long that the transactional data in the tempdb filled.</p>
  
  <p>I would like to prevent this in the future by adding logic to my query that checks to see if tempdb is nearing its threshold, and if so ends the query. Is this possible?</p>