title: How to check existence of a sql server object and drop it?
body: <p><strong>EDIT</strong>: the function creation was missing, sorry about that</p>
  
  <p>I have a T-SQL request that goes:</p>
  
  <pre><code>DECLARE @IsSomething bit
  SET @IsSomething = 0
  IF /some tests/ SET @IsSomething = 1
  EXEC('
  CREATE FUNCTION IsSomething ()
  RETURNS bit
  AS
  BEGIN
      RETURN ' + @IsSomething + '
  END')
  </code></pre>
  
  <p>Of course if I run it twice I get </p>
  
  <pre><code>There is already an object named 'IsSomething ' in the database. 
  </code></pre>
  
  <p>How would I do something like this:</p>
  
  <pre><code>IF EXIST @IsSomething DESTROY @IsSomething // (Pseudo bad code)
  </code></pre>