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 |
ahouse
Starting Member
27 Posts |
Posted - 2008-12-22 : 13:44:12
|
Hi, I am working on a piece of coding that loops thru each client and processes a file containing their lines of information from the table. Once all clients have been looped thru, the stored proc should finish. I am testing this with Query AnalyzerI am using the field WasProcessed to control this. When the file is initially created, WasProcessed is set to zero for everything. Then as files get pushed (using dts calls) they are set to something other than zero. For testing purposes, I have replaced the dts calls with UPDATE statements so I can see what is happening. The query analyzer always reports back to me(1 row(s) affected)(XX row(s) affected) (depending on number of rows for that client)It should loop thru and do this for each client. Not just the first one it comes to. Any help is appreciated. Thanks everyone!Andrew--Declare VariablesDeclare @CurrentProgramID intDeclare @CurrentClientID intDeclare @AccountsTilCompletion intDeclare @CurrentReturnName char(15)Declare @CurrentReturnType int--Initialize variables to begin looping through locatesSet @CurrentProgramID = (Select Min(ProgramID) From DailyLocates Where DailyLocates.WasProcessed = 0)Set @CurrentClientID = (Select Min(ClientID) From DailyLocates Where DailyLocates.ProgramID = @CurrentProgramID)Set @AccountsTilCompletion = (Select Count(*) From DailyLocates Where DailyLocates.WasProcessed = 0)--Loop until all Located Accounts have been processedWhile (@AccountsTilCompletion > 0)Begin Set @CurrentProgramID = (Select Min(ProgramID) From DailyLocates Where DailyLocates.WasProcessed = 0); Set @CurrentReturnName = (Select distinct(ReturnName) From DailyLocates Where DailyLocates.ProgramID = @CurrentProgramID); Set @CurrentReturnType = (Select Min(ReturnTypeID) From DailyLocates Where DailyLocates.ProgramID = @CurrentProgramID); --Invoke DTS packages to run based on ReturnFile Type Begin Select @CurrentReturnType If @CurrentReturnType = 0 GoTo CatchTheException; If @CurrentReturnType = 1 GoTo CreateXLSReturn; If @CurrentReturnType = 2 GoTo CreateTextReturn; If @CurrentReturnType = 3 GoTo CreatePDFReturn; If @CurrentReturnType = 4 GoTo CreateCSVReturn; If @CurrentReturnType = 5 GoTo CreateFaxReturn; If @CurrentReturnType = 6 GoTo CreateXLSPDFReturn; End --Loop until DTS package has completed --When DTS package completes, DailyLocates.WasProcessed will be set to '1' on all current accounts and this loop will end While((Select Count(*) From DailyLocates Where DailyLocates.WasProcessed = 0 AND DailyLocates.ProgramID = @CurrentProgramID) > 0) Begin WaitFor Delay '00:00:02'; End Set @CurrentProgramID = (Select Min(ProgramID) From DailyLocates Where DailyLocates.WasProcessed = 0); Set @AccountsTilCompletion = (Select Count(*) From DailyLocates Where DailyLocates.WasProcessed = 0);EndCatchTheException: Update DailyLocates Set WasProcessed = 2 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreateXLSReturn: Update DailyLocates Set WasProcessed = 3 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreateTextReturn: Update DailyLocates Set WasProcessed = 4 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreatePDFReturn: Update DailyLocates Set WasProcessed = 5 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreateCSVReturn: Update DailyLocates Set WasProcessed = 6 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreateFaxReturn: Update DailyLocates SET WasProcessed = 7 Where DailyLocates.ProgramID = @CurrentProgramIDReturnCreateXLSPDFReturn: Update DailyLocates Set WasProcessed = 8 Where DailyLocates.ProgramID = @CurrentProgramIDReturnGO |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
ahouse
Starting Member
27 Posts |
Posted - 2008-12-22 : 15:11:28
|
I added the print statements periodically and found that my procedure never gets past the function call. Is it legal to use nested Begin and End statements? Are my functions missing a piece allowing them to return to the while loop to finish executing?--Invoke DTS packages to run based on ReturnFile Type Begin Select @CurrentReturnType If @CurrentReturnType = 0 GoTo CatchTheException; If @CurrentReturnType = 1 GoTo CreateXLSReturn; If @CurrentReturnType = 2 GoTo CreateTextReturn; If @CurrentReturnType = 3 GoTo CreatePDFReturn; If @CurrentReturnType = 4 GoTo CreateCSVReturn; If @CurrentReturnType = 5 GoTo CreateFaxReturn; If @CurrentReturnType = 6 GoTo CreateXLSPDFReturn; EndPrint @CurrentReturnTypePrint @AccountsTilCompletion |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-12-22 : 15:32:06
|
quote: Originally posted by ahouse I added the print statements periodically and found that my procedure never gets past the function call. Is it legal to use nested Begin and End statements? Are my functions missing a piece allowing them to return to the while loop to finish executing?--Invoke DTS packages to run based on ReturnFile Type Begin Select @CurrentReturnType If @CurrentReturnType = 0 GoTo CatchTheException; If @CurrentReturnType = 1 GoTo CreateXLSReturn; If @CurrentReturnType = 2 GoTo CreateTextReturn; If @CurrentReturnType = 3 GoTo CreatePDFReturn; If @CurrentReturnType = 4 GoTo CreateCSVReturn; If @CurrentReturnType = 5 GoTo CreateFaxReturn; If @CurrentReturnType = 6 GoTo CreateXLSPDFReturn; EndPrint @CurrentReturnTypePrint @AccountsTilCompletion
Thats not a function that you are using. Those are labels instead. GOTO statement is taking you out of the loop to CatchTheException,CreateXLSReturn etc. You should rework the logic that you are using here. |
|
|
ahouse
Starting Member
27 Posts |
Posted - 2008-12-22 : 16:50:28
|
Thank you, I didn't realize the calls would not return me to the loop. I've replaced the GoTo statement with the actual code to be executed and it is working correctly now. Rookie mistake on my part thank you both for your help.Happy Holidays |
|
|
|
|
|