I have declared the veriable, set the variable, and the second query fails with the error message of
Must declare the scalar variable "@YYYYMM".
USE [DatabaseName]
GO
DECLARE @YYYYMM INT
SET @YYYYMM = 201305
/**** UPDATE TRAILING PROJECT STATUS ****/
UPDATE ptd
SET ptd.Status = 'T'
FROM dbo.CTC_PTD ptd
INNER JOIN dbo.CTC_FINISHED fin ON ptd.strProject = fin.strProject AND ptd.[System] = fin.[System]
WHERE ptd.FiscalPeriod = @YYYYMM AND fin.Finished_Period < @YYYYMM
GO
/**** UPDATE TIP INTO CTC_PTD ****/
UPDATE ctc
SET ctc.Current_TIP_Approved = tip.TIP_Amount, ctc.TIP = tip.TIP_Current, ctc.PTD_TIP = tip.TIP_Current + tip.TIP_Previous
FROM dbo.CTC_PTD ctc
INNER JOIN TIP_RECOGNITION tip ON ctc.strProject = tip.strProject AND ctc.[System] = tip.[System] AND ctc.FiscalPeriod = tip.FiscalPeriod
WHERE ctc.FiscalPeriod = @YYYYMM
GO
IS a variable only good once? Do i have to create a procedure or a function?
If I do create a procedure or function, where do I save it?
I have A book, but this detail is missing from the chapter. . .
thanks,
sportsguy
MS Access 20 years, SQL hack