I have the following stored procedure that checks if a table exists and drops it. Then it Selects into a new table by the same name and adds indexes to it. The problem is that when I run the query to create the SP, I get this error:Msg 2714, Level 16, State 6, Line 2There is already an object named 'MSDN_Alldata' in the database.Here is the SP:ALTER PROCEDURE CreateAndPopulate_MSDN_AllData ASIF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MSDN_Alldata]') AND type in (N'U'))DROP TABLE [dbo].[MSDN_Alldata]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOselect dt.* into MSDN_Alldata from (select distinct d.* from (select MSDN.Email, H.* from MSDN_Email MSDNleft join HR_NSV_PM H on H.Email_ID = MSDN.Email) dwhere nullif(d.emplid,'') is not nullunion allselect 'MSDN email NOT Found - Name Match' as Email, h.* from (select distinct MSDN.Email, MSDN.First_Name FN, MSDN.Last_Name LN, H.* from MSDN_Email MSDNleft join HR_NSV_PM H on H.Email_ID = MSDN.Emailwhere nullif(H.EMPLID,'') is null) dleft join HR_NSV_PM h on h.LAST_NAME = d.LN and h.FIRST_NAME = d.FNWHERE NULLIF(h.EMPLID,'') IS NOT NULL) dtorder by CASE WHEN dt.Email Like 'MSDN%' THEN 1 ELSE 0 END, CASE WHEN nullif(dt.EMPLID,'') IS NULL THEN 1 ELSE 0 END, dt.LAST_NAME, dt.FIRST_NAMECREATE INDEX idx_MSDN_AllData_EMPLIDON dbo.MSDN_AllData( EMPLID)GOCREATE INDEX idx_MSDN_AllData_EMAILON dbo.MSDN_AllData( EMAIL)GOCREATE INDEX idx_MSDN_AllData_LAST_NAMEON dbo.MSDN_AllData( LAST_NAME)GOCREATE INDEX idx_MSDN_AllData_FIRST_NAMEON dbo.MSDN_AllData( FIRST_NAME)GOCREATE INDEX idx_MSDN_AllData_AUON dbo.MSDN_AllData( AU)GOCREATE INDEX idx_MSDN_AllData_AU_NAMEON dbo.MSDN_AllData( AU_NAME)GO
This happens when I just create or alter the procedure. Ironically, the SP is actually created, but why the error? I didn't try to run it and even if I did, the script says to drop the table first anyway. Now, when I script this procedure (that was created evidently with errors), I get this:USE [SoftwareReporting]GO/****** Object: StoredProcedure [dbo].[CreateAndPopulate_MSDN_AllData] Script Date: 06/03/2010 15:21:28 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CreateAndPopulate_MSDN_AllData]') AND type in (N'P', N'PC'))BEGINEXEC dbo.sp_executesql @statement = N' -- Select into new table MSDN_AllData -- All MSDN rows, All columns - includes Email matches and Name matches -- name matches have duplicates as there are more than 1 name to match an EMPLID in HRCREATE PROCEDURE [dbo].[CreateAndPopulate_MSDN_AllData] ASIF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[MSDN_Alldata]'') AND type in (N''U''))DROP TABLE [dbo].[MSDN_Alldata]' ENDGO
It cut off most of the procedure. I will appreciate if someone can tell me what's happening and what to do about it.Duane