declare @siSourceID int
SELECT si.SourceID
INTO #tmpSourceIds
FROM tblSourceInfo si
while exists (select 1 from #tmpSourceIds)
BEGIN
SELECT TOP 1 @siSourceID = t.SourceID
FROM #tmpSourceIds
BEGIN TRY
INSERT INTO tblInfo
(
facility_id,
sys_loc_code,
well_id,
well_status,
construct_start_date,
depth_of_well,
top_casing_elev,
well_purpose,
remark
)
SELECT
si.facility,
si.SourceID,
si.SourceName,
si.Status,
si.DrillDate,
si.TDW,
si.MPE,
si.SourceType,
si.SourceInfoComments
FROM tblSourceInfo si
WHERE si.SourceId = @siSourceID
END TRY
BEGIN CATCH
INSERT INTO tblErrors
VALUES (@siSourceID)
END CATCH
Delete from #tmpSourceIds where SourceId = @siSourceID;
END
|