title: Already an object named in the database issue
body: <p>I am trying to execute an email that contains the results of a stored procedure. I was looking at other posts in stackoverflow but cannot seem to get past an error that states "Msg 2714, Level 16, State 1, Procedure CompareConfirm_FraudRules, Line 38
  There is already an object named '##returnInactiveRules' in the database."  I've looked in the DB and there is no object that exists with this name already. Any suggestions on how to fix this issue would be appreciated.  Thanks.</p>
  
  <p>Here is the my SP:</p>
  
  <pre><code>BEGIN
  
  CREATE TABLE ##returnInactiveRules (
      ProductName varchar(100),
      ChannelName varchar(100),
      StrategyCode varchar(100),
      StrategyName varchar(100),
      RuleCode varchar(100),
      RuleName varchar(100),
      On_Off varchar(5)
  );
  
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  SET NOCOUNT ON;
  
  -- Insert statements for procedure here
  -- SELECT R.RuleCode, R.Name as RuleName, S.StrategyCode, S.Name as StrategyName, R.IsActive
  SELECT DISTINCT
      CASE
      WHEN PC.ProductIdentifier='2000' THEN 'GP'
      WHEN PC.ProductIdentifier='1000' THEN 'MB'
      END as ProductName, C.Name as ChannelName, S.StrategyCode, S.Name as StrategyName, R.RuleCode, R.Name as RuleName, 
      CASE
      WHEN R.IsActive = 1 THEN 'On'
      WHEN R.IsActive = 0 THEN 'Off'
      END as On_Off
  INTO ##returnInactiveRules
  FROM dbo.[Rule] R
  INNER JOIN dbo.Strategy S  
  on S.KnockoutRuleSet = R.KnockoutRuleSet 
  INNER JOIN dbo.RFAI P 
  on R.RFAIId = P.RFAIId
  INNER JOIN dbo.DecisionStatus D 
  on D. StatusId = R. StatusId
  LEFT OUTER JOIN dbo.NOAA N 
  on N.NOAAId = R.NOAAId
  INNER JOIN dbo.RuleQuestionsXRef Q 
  ON Q.RuleId = R.RuleId
  INNER JOIN ProductChannelStrategyRuleXref X 
  ON X.RuleId = R.RuleId 
  INNER JOIN ProductChannelStrategy CS 
  ON CS.ProductChannelStrategyId = X.ProductChannelStrategyId
  INNER JOIN ProductChannel PC
  ON PC.ProductChannelId = CS.ProductChannelId
  INNER JOIN dbo.Channel C
  ON C.ChannelId = PC.ChannelId
  WHERE R.IsActive = 0
  AND R.RuleCode IN ('F06',
  'F07',
  'F11',
  'F12',
  'F14',
  'F15',
  'F16',
  'F17',
  'F19',
  'F23',
  'F25',
  'F26',
  'F10'
  )  
  -- ORDER BY R.RuleCode, R.Name;
  ORDER BY ProductName, C.Name, S.StrategyCode, S.Name, R.RuleCode, R.Name;
  
  -- SELECT * FROM @returnValue;
  
  -- Email the results in the @returnValue table -- 
      EXEC msdb.dbo.sp_send_dbmail
      @execute_query_database='Prod-XXX',
      @recipients=N'msavoy@xxx.com',
      @body='Attached please find a file with the results.', 
      @subject ='Compare Fraud Rule Results',
      @profile_name ='Reports',
      @query ='EXEC CompareConfirm_Rules',
      @attach_query_result_as_file = 1,
      @query_attachment_filename ='CompareRuleResults.txt'
  END
  DROP TABLE ##returnInactiveRules;
  GO
  </code></pre>