Когда я запускаю скрипт ниже, я получаю это исключение. Он разбился примерно через 20 минут (+/- пару минут). Как я могу предотвратить это исключение, не создавая пакеты? Я хочу сделать это для всех клиентских записей, которым это необходимо.
Исключение:
An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown.
Сценарий преобразования SQL:
SELECT clientid
INTO #Temp
FROM client
DECLARE
@iteratorId INT,
@phone NVARCHAR(64),
@fax NVARCHAR(64),
@contactid INT
WHILE (SELECT Count(*) FROM #Temp) > 0
BEGIN
SELECT TOP 1 @iteratorId = clientid FROM #Temp
SET @contactid = NULL
--try and grab the first non null phone number in priority order
SET @phone = ISNULL((
SELECT TOP 1
dayphone
FROM contact c
INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid
WHERE
clientid = @iteratorId
AND cc.contacttypeid=2
AND c.dayphone IS NOT NULL
ORDER BY cc.parentclientcontactid, priority DESC
),'')
--try and grab the first non null fax priority order
SET @fax = ISNULL((
SELECT TOP 1
fax
FROM contact c
INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid
WHERE
clientid = @iteratorId
AND cc.contacttypeid=2
AND c.fax IS NOT NULL
ORDER BY cc.parentclientcontactid, priority DESC
),'')
IF NOT EXISTS(SELECT * FROM clientcontact WHERE clientid=@iteratorId AND contacttypeid=3 AND priority=1)
BEGIN
INSERT INTO dbo.contact
( versionnumber ,
createdate ,
firstname ,
lastname ,
title ,
middleinitial ,
dayphone ,
nightphone ,
mobilephone ,
fax ,
securefax ,
extranetusername ,
extranetpassword ,
email ,
active ,
testfaxpagereceived ,
ftpoptionid ,
testresultnotify
)
VALUES ( 0 , -- versionnumber - int
GETDATE() , -- createdate - datetime
NULL , -- firstname - nvarchar(64)
NULL , -- lastname - nvarchar(64)
NULL , -- title - nvarchar(64)
NULL , -- middleinitial - nvarchar(64)
NULL , -- dayphone - nvarchar(64)
NULL , -- nightphone - nvarchar(64)
NULL , -- mobilephone - nvarchar(64)
NULL , -- fax - nvarchar(64)
'' , -- securefax - bit
NULL , -- extranetusername - nvarchar(64)
NULL , -- extranetpassword - nvarchar(64)
NULL , -- email - nvarchar(127)
0 , -- active - bit
0 , -- testfaxpagereceived - bit
NULL , -- ftpoptionid - int
NULL -- testresultnotify - bit
)
SET @contactid = @@IDENTITY
EXEC dbo.procContactSave
@contactid = @contactid, -- int
@firstname = "General", -- nvarchar(64)
@middleinitial = NULL, -- nvarchar(64)
@nightphone = NULL, -- nvarchar(64)
@lastname = "Info", -- nvarchar(64)
@email = NULL, -- nvarchar(127)
@fax = @fax, -- nvarchar(64)
@testfaxpagereceived = 0, -- bit
@mobilephone = NULL, -- nvarchar(64)
@securefax = 0, -- bit
@active = 1, -- bit
@extranetpassword = NULL, -- nvarchar(64)
@extranetusername = NULL, -- nvarchar(64)
@title = NULL, -- nvarchar(64)
@ftpoptionid = NULL, -- int
@dayphone = @phone, -- nvarchar(64)
@testresultnotify = 0, -- bit
@audituserid = 0 -- int
EXEC dbo.procClientContactSave
@clientcontactid = NULL, -- int
@priority = 1, -- int
@clientid = @iteratorId, -- int
@contacttypeid = 3, -- int
@contactid = @contactid, -- int
@audituserid = 0 -- int
END
DELETE #Temp Where clientid = @iteratorId -- delete row so we don't loop over it again
END
DROP TABLE #Temp