Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sportsguy
Starting Member
39 Posts |
Posted - 2013-03-05 : 14:17:40
|
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]GODECLARE @YYYYMM INTSET @YYYYMM = 201305/**** UPDATE TRAILING PROJECT STATUS ****/UPDATE ptdSET 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 < @YYYYMMGO/**** UPDATE TIP INTO CTC_PTD ****/UPDATE ctcSET ctc.Current_TIP_Approved = tip.TIP_Amount, ctc.TIP = tip.TIP_Current, ctc.PTD_TIP = tip.TIP_Current + tip.TIP_PreviousFROM dbo.CTC_PTD ctc INNER JOIN TIP_RECOGNITION tip ON ctc.strProject = tip.strProject AND ctc.[System] = tip.[System] AND ctc.FiscalPeriod = tip.FiscalPeriodWHERE 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,sportsguyMS Access 20 years, SQL hack |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-03-05 : 14:23:31
|
The GO is the end of a batch and after that the vars are unknown. Too old to Rock'n'Roll too young to die. |
|
|
sportsguy
Starting Member
39 Posts |
Posted - 2013-03-05 : 16:35:22
|
webfredTHANKS! i didn't see that in the book, but i tried it and worked perfectly!makes sense as well. . .MS Access 20 years, SQL hack |
|
|
|
|
|