| Author |
Topic |
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-08 : 02:43:48
|
| This should be a lot easier than I am making it... all I want to do is take the int value in a column and add it to a variable. This is a variation of a count function. I am wanting this procedure to loop until the variable @iteration reaches a certain number. I don't really care how many times it loops, just keep looping until @iteration reaches a given #.SET @iteration = (@interation + [size] from [orcxpdb1c2\sql].GlobalDBAServer.dbo.BackupHistory where @newserver = [Server] and @newdbname = [database])---------------------------Working until "the morning sun sets the midnight sky on fire"! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-08 : 02:47:49
|
| [code]SELECT @iteration = @interation + [size] from [orcxpdb1c2\sql].GlobalDBAServer.dbo.BackupHistory where [Server] =@newserver and [database]=@newdbnameand @iteration <=your limit here[/code] |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-08 : 02:49:09
|
| I received this error when I added the above code:Incorrect syntax near the keyword 'from'.---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-08 : 02:51:53
|
| i'm not getting it. can you post our full query? |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-08 : 03:13:40
|
| Sorry, you posted while I was posting, I was referring to my original post. The result of your code is unexpected. The PRINT for @iteration before your code is "1". after your code it prints "155189248", but the [size] field is only "1703936" and it only loops once.It makes no difference if I comment out your last line. The entire script starts (after declarations) with While @iteration <= 5000000This bit of code is at the very end.---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-08 : 05:34:38
|
| can you post entire script here to be clear please ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-08 : 08:31:23
|
quote: Originally posted by GRAYWOLF Sorry, you posted while I was posting, I was referring to my original post. The result of your code is unexpected. The PRINT for @iteration before your code is "1". after your code it prints "155189248", but the [size] field is only "1703936" and it only loops once.It makes no difference if I comment out your last line. The entire script starts (after declarations) with While @iteration <= 5000000This bit of code is at the very end.---------------------------Working until "the morning sun sets the midnight sky on fire"!
do you mean you're doing this inside a loop? why are you looping this? can you explain what you're trying to do here? |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-09 : 02:55:25
|
| I am working on an automated restore to test backups. The code starts with declarations. Then a while loop controls the rest of the process. It pulls the server, DB and backup file path from a table. It makes necessary path changes.Determines whether it is a single or split backup file.Determines if it is a Red Gate or native backup.Runs the restore.Runs a test on it.Deletes the DB. Trying to get it to add the size of the db to @iteration and start over as long as the value of @iteration is less than whatever we set the While loop limit to.The part that is giving me trouble is that I have to pull the size from another table and add that to @iteration---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-09 : 02:57:43
|
| Running WHILE @iteration <= 10BEGIN... 350 lines of code...SET @iteration = @iteration + 1ENDeverything works as desired. I am trying to set the script so that it will loop until it has reached 5GB (or whatever) of data restored.WHILE @iteration <= 5000000000BEGIN... 350 lines of code...SELECT @iteration = @iteration + [size] FROM [server\sql].GlobalDBAServer.dbo.BackupHistory WHERE [Server] =@newserver and [database]=@newdbnameEND---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-09 : 03:17:32
|
SELECT @iteration = @iteration + coalesce([size] ,0)FROM [server\sql].GlobalDBAServer.dbo.BackupHistory WHERE [Server] =@newserver and [database]=@newdbnamemaybe? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-01-09 : 03:58:05
|
| That did it...thanks!---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
|