What I am trying to do is execute the stored procedure below automatically via a Maintenance Plan using the Execute T-SQL Statement Task. What I am seeing is that when this procedure runs as part of a maintenance plan, for some reason, the records added are doubled, as though the INSERT statement is run twice. Here's the kicker, when it is executed manually via Management Studio, it runs as expected and I get a single set of records added to the table. Using TRUNCATE TABLE as a work-around seems to solve the problem but I will be back to square one when it comes time to prepare the database for SQL mirroring.
Has anyone seen this sort of behavior before? Also, for the curious, the 100% fill factor on the rebuilt index is intentional because the only I/O happening on this table is the procedure below.
ALTER PROCEDURE [dbo].[usp_Populate_SearchTable]
AS
BEGIN
UPDATE ut_Update_Status SET [status] = 1, lastUpdate = getdate();
DELETE FROM ut_Permit_Lookup;
DBCC CHECKIDENT ('dbo.ut_Permit_Lookup', RESEED, 0);
-- OR
--TRUNCATE TABLE ut_Permit_Lookup;
INSERT INTO ut_Permit_Lookup (
NUMBER_KEY,
ADDR_FRACTION,
PARCEL_NO,
TYPE_TITLE,
TypDesc,
SUB_TYPE,
Location,
[DESCRIPTION],
DATE_A,
DATA_STATUS
)
SELECT a.NUMBER_KEY,
a.ADDR_FRACTION,
a.PARCEL_NO,
a.TYPE_TITLE,
a.TypDesc,
a.SUB_TYPE,
a.Location,
SUBSTRING(a.[DESCRIPTION], 1, 275),
a.DATE_A,
a.DATA_STATUS
FROM PERMPLUS.dbo.vw_Permit_WebLookup as a
WHERE a.TYPE_CAT = 'BLDG'
AND a.DATA_LEVEL = 'A'
AND (a.CLASS <> 'NA' OR a.CLASS IS NULL);
DBCC DBREINDEX ('dbo.ut_Permit_Lookup', idx_SearchIndex, 100);
UPDATE ut_Update_Status SET [status] = 0;
END