HestonJames
Programmer
Hello Guys,
I've got this import script here which takes a bunch of data, sticks it in a temporary staging table and then move the lot into the correct tables, buiding FK's and whatnot.
On occasion when this code is being run I'm recieving the following error message:
Now, this is of no real concequence to me as I'm catch the error and retrying the import a few moments later and it all goes in fine, however, I'd still like to get to the bottom of what is causing this issue.
Can anyone make any reccomendations on this? I'd really appreciate it.
One thing to note, this is not actualy a global temp table ## the code comes from an Adobe ColdFusion query block and I have to ## to escape the pound, its actualy only producing a single # in the block in the generated SQL.
Cheers,
Heston
I've got this import script here which takes a bunch of data, sticks it in a temporary staging table and then move the lot into the correct tables, buiding FK's and whatnot.
Code:
CREATE TABLE ##MessageStaging (
DeviceAddress char(17) Collate Database_Default,
PushPort smallint ,
LogDateTime datetime,
LogClass_ID int,
Media_ID int,
Campaign_ID int
)
[b]loop and import data into the temp table.[/b]
INSERT
INTO OUI
( OUI
, Manufacturer )
SELECT DISTINCT LEFT(##MessageStaging.DeviceAddress, 8)
, 'Unknown OUI, ' + CONVERT(VARCHAR(25), GETDATE(), 121)
FROM ##MessageStaging
LEFT OUTER
JOIN OUI
ON OUI.OUI = LEFT(##MessageStaging.DeviceAddress, 8)
WHERE OUI.OUI IS NULL
INSERT
INTO Device
( OUI_ID
, Address
, PushPort )
SELECT DISTINCT
OUI.OUI_ID
, SUBSTRING(##MessageStaging.DeviceAddress,10,8)
, ##MessageStaging.PushPort
FROM ##MessageStaging
INNER
JOIN OUI
ON OUI.OUI = left(##MessageStaging.DeviceAddress,8)
LEFT OUTER
JOIN Device
ON Device.OUI_ID = OUI.OUI_ID
AND Device.Address = SUBSTRING(##MessageStaging.DeviceAddress,10,8)
WHERE Device.OUI_ID IS NULL
UPDATE Device
SET PushPort = ##MessageStaging.PushPort
FROM ##MessageStaging
INNER
JOIN OUI
ON OUI.OUI = left(##MessageStaging.DeviceAddress,8)
INNER
JOIN Device as D2
ON D2.OUI_ID = OUI.OUI_ID
AND D2.Address = SUBSTRING(##MessageStaging.DeviceAddress,10,8)
AND ( D2.PushPort IS NULL
or D2.PushPort <> ##MessageStaging.PushPort )
INSERT
INTO MessageLog
( Device_ID
, LogDateTime
, LogClass_ID
, Media_ID
, Campaign_ID
, ThinkTank_ID )
SELECT Device.Device_ID
, ##MessageStaging.LogDateTime
, ##MessageStaging.LogClass_ID
, ##MessageStaging.Media_ID
, ##MessageStaging.Campaign_ID
, '#LOCAL.tank_id#'
FROM ##MessageStaging
INNER
JOIN OUI
ON OUI.OUI = LEFT(##MessageStaging.DeviceAddress,8)
INNER
JOIN Device
ON Device.OUI_ID = OUI.OUI_ID
AND Device.Address = SUBSTRING(##MessageStaging.DeviceAddress,10,8)
On occasion when this code is being run I'm recieving the following error message:
Transaction (Process ID 61) was deadlocked on lock resources with another process and has been chosen as the deadlock victim
Now, this is of no real concequence to me as I'm catch the error and retrying the import a few moments later and it all goes in fine, however, I'd still like to get to the bottom of what is causing this issue.
Can anyone make any reccomendations on this? I'd really appreciate it.
One thing to note, this is not actualy a global temp table ## the code comes from an Adobe ColdFusion query block and I have to ## to escape the pound, its actualy only producing a single # in the block in the generated SQL.
Cheers,
Heston