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 |
|
MTater
Starting Member
2 Posts |
Posted - 2010-09-14 : 20:19:20
|
| Hi- I get stuck at SELECT @StartTime = getdate() when I try and run this script. Get error Msg 137, Level 15, State 1, Line 1Must declare the scalar variable "@StartTime". How do I run this? It should work. . . I must not be breaking it up right or ???DECLARE @Counter intDECLARE @RowsProcessed int, @MaxCount intSET @Counter = 0 -- Start of real recordsSET NOCOUNT ONSELECT @MaxCount = MAX(PrimaryID) FROM dbo.OEM_RtoS_Returns_WorkingStartOfLoop:SELECT @StartTime = getdate()-- Increment the control counter so 1,000 rows are operated on at a time.SET @Counter = @Counter + 1000INSERT OEM_RtoS_ResultSELECT DISTINCT r.BeginningCOAID AS ReturnCOAID, s.BeginningCOAID AS ShipBegCOAID, s.EndingCOAID AS ShipEndCOAIDFROM dbo.OEM_RtoS_Returns_Working rLEFT JOIN OEM_RtoS_Shipments sON r.First11Chars = s.First11CharsAND r.Last6BegCOAID >= s.Last6BegCOAIDAND r.Last6BegCOAID <= s.Last6EndCOAIDWHERE r.PrimaryID <= @CounterSET @RowsProcessed = @@ROWCOUNTDELETE FROM OEM_RtoS_Returns_WorkingWHERE PrimaryID <= @CounterSELECT @LoopTime = getdate()SELECT @MSG = 'Batch counter = (' + CONVERT(varchar, @Counter) + ') ' + CONVERT(varchar, @RowsProcessed) + ' Records processed in (' + CONVERT(varchar,(DATEDIFF(Minute, @StartTime, @LoopTime))) + ') Minutes'RAISERROR(@MSG,1,1) WITH NOWAIT-- IF (@Counter >= @MaxCount) BEGIN GOTO EndOfLoop ENDGOTO StartOfLoopEndOfLoop:END |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-09-15 : 02:29:01
|
Hello,quote:
Hi- I get stuck at SELECT @StartTime = getdate() when I try and run this script. Get error Msg 137, Level 15, State 1, Line 1Must declare the scalar variable "@StartTime".
You must declare the scalar variable "@StartTime".  quote: DECLARE @Counter intDECLARE @RowsProcessed int, @MaxCount intDECLARE @StartTime datetime....................
Best regards,Devart,SQL Server Tools:dbForge Schema ComparedbForge Data ComparedbForge Query Builder |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-15 : 03:08:09
|
| You can useDECLARE @Counter intDECLARE@RowsProcessed int,@MaxCount int,@StartTime datetime |
 |
|
|
MTater
Starting Member
2 Posts |
Posted - 2010-09-15 : 15:40:36
|
| Ok cool thank you very much. So that does jive with the very beginning piece of the overall script although that one doesn't run. I get this error:Msg 1018, Level 15, State 1, Procedure OEMFY10_Q4_Part1_MatchReturnsToShipments, Line 20Incorrect syntax near 'NOWAIT'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.when running:IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[OEMFY10_Q4_Part1_MatchReturnsToShipments]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)BEGIN DROP PROCEDURE [OEMFY10_Q4_Part1_MatchReturnsToShipments]ENDGO-- OEMFY10_Q4_Part1_MatchReturnsToShipmentsCREATE PROCEDURE dbo.OEMFY10_Q4_Part1_MatchReturnsToShipmentsASBEGINDECLARE @StartTime datetime, @LoopTime datetime, @MSG varchar(255), @SQLString nvarchar(4000), @ErrorDescr varchar(255)SELECT @ErrorDescr = ''SELECT @StartTime = getdate()SELECT @MSG = 'Start of OEMFY10_Q4_Part1_MatchReturnsToShipments Process(' + CONVERT(varchar,@startTime) + ')'RAISERROR(@MSG,1,1) WITH NOWAIT |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-09-15 : 16:20:34
|
Do you know what books online is?BOL:quote: C. Using a local variable to supply the message textThe following code example shows how to use a local variable to supply the message text for a RAISERROR statement. Copy Code DECLARE @StringVariable NVARCHAR(50);SET @StringVariable = N'<<%7.3s>>';RAISERROR (@StringVariable, -- Message text. 10, -- Severity, 1, -- State, N'abcde'); -- First argument supplies the string.-- The message text returned is: << abc>>.GO
I don't think you need NOWAITBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|