jgoodman00
Programmer
- Jan 23, 2001
- 1,510
I have an sp as follows:
CREATE PROCEDURE dbo.sp_Bramble_UPD_InspDates
(@InspectionDate DateTime, @Surveyor int, @InspectionType int)--, @RowsInserted int output, @RowsUpdated int output)
AS
INSERT INTO dbo.HISTORY_tblAssetBramble
(RefNoL, IdentifiedWorksNumber, Spray, Cutdown, RemoveUnwantedSpecies, VisitsPerYear, ReplantingRequired, Retain, DesignRequired,
KillBramble, SoilID, HeightM, InspectionDate, InspectionTypeID, SurveyorID, Priority, Remarks, Budget, Rate)
SELECT RefNo, IdentifiedWorksNumber, Spray, Cutdown, RemoveUnwantedSpecies, VisitsPerYear, ReplantingRequired, Retain, DesignRequired,
KillBramble, SoilID, HeightM, InspectionDate, InspectionTypeID, SurveyorID, Priority, Remarks, Budget, Rate
FROM dbo.qryBramble_Form
WHERE (Priority = 'A' OR Priority = 'B' Or Priority = 'C' OR Priority = 'D' OR Priority = 'E')
AND (DateDiff(mm,[InspectionDate],GetDate()) > 2)
--SET @RowsInserted = @@RowCount
UPDATE dbo.qryBramble_Form
SET InspectionDate = @InspectionDate, SurveyorID = @Surveyor, InspectionTypeID = @InspectionType
FROM dbo.qryBramble_Form
WHERE Priority = 'A' OR Priority = 'B' Or Priority = 'C' OR Priority = 'D' OR Priority = 'E'
--SET @RowsUpdated = @@RowCount
GO
As a test, I have tried adding (below the first batch):
INSERT INTO dbo.tblEnvironmentalHistory (RefNo, ModField, OldValue, NewValue)
SELECT RefNo, 'InspectionDate', InspectionDate, @InspectionDate
FROM dbo.qryBramble_Form
However, it seems the @InspectionDate variable goes out of scope when the first batch is executed. According to the help file, a local variable declared within a batch will not be available outside the batch, but to me this looks like the variable is being declared outside the batch, & as a procedure-level variable, which should be in scope.
James Goodman MCP
CREATE PROCEDURE dbo.sp_Bramble_UPD_InspDates
(@InspectionDate DateTime, @Surveyor int, @InspectionType int)--, @RowsInserted int output, @RowsUpdated int output)
AS
INSERT INTO dbo.HISTORY_tblAssetBramble
(RefNoL, IdentifiedWorksNumber, Spray, Cutdown, RemoveUnwantedSpecies, VisitsPerYear, ReplantingRequired, Retain, DesignRequired,
KillBramble, SoilID, HeightM, InspectionDate, InspectionTypeID, SurveyorID, Priority, Remarks, Budget, Rate)
SELECT RefNo, IdentifiedWorksNumber, Spray, Cutdown, RemoveUnwantedSpecies, VisitsPerYear, ReplantingRequired, Retain, DesignRequired,
KillBramble, SoilID, HeightM, InspectionDate, InspectionTypeID, SurveyorID, Priority, Remarks, Budget, Rate
FROM dbo.qryBramble_Form
WHERE (Priority = 'A' OR Priority = 'B' Or Priority = 'C' OR Priority = 'D' OR Priority = 'E')
AND (DateDiff(mm,[InspectionDate],GetDate()) > 2)
--SET @RowsInserted = @@RowCount
UPDATE dbo.qryBramble_Form
SET InspectionDate = @InspectionDate, SurveyorID = @Surveyor, InspectionTypeID = @InspectionType
FROM dbo.qryBramble_Form
WHERE Priority = 'A' OR Priority = 'B' Or Priority = 'C' OR Priority = 'D' OR Priority = 'E'
--SET @RowsUpdated = @@RowCount
GO
As a test, I have tried adding (below the first batch):
INSERT INTO dbo.tblEnvironmentalHistory (RefNo, ModField, OldValue, NewValue)
SELECT RefNo, 'InspectionDate', InspectionDate, @InspectionDate
FROM dbo.qryBramble_Form
However, it seems the @InspectionDate variable goes out of scope when the first batch is executed. According to the help file, a local variable declared within a batch will not be available outside the batch, but to me this looks like the variable is being declared outside the batch, & as a procedure-level variable, which should be in scope.
James Goodman MCP