473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Variable in while loop not getting incremented

1
Hi,

This is my code.

create trigger addDnsRecord_staticIphost
on staticIPHost
for insert, update
as
begin
declare @EthMac varchar(255)
declare @hostname varchar(255)
declare @ipAddr varchar(255)
declare @cpeMac varchar(255)
declare @command varchar(255)
declare @numOfHosts int
declare @numHosts_Str varchar(255)
set @numOfHosts = 0

declare mycursor cursor
for select * from inserted
open mycursor
fetch next from mycursor into @EthMac, @cpeMac, @ipAddr
while (@@fetch_status=0)
begin
set @numOfHosts = @numOfHosts + 1
select @hostname = (select serialNumber from cpe where cpeMac=@cpemac)
select @numHosts_Str = cast(@numOfHosts as varchar(255))
set @command = 'c:\batchscripts\addDnsRecord ' + @hostname + '_'+ @numHosts_Str + ' '+ @ipAddr
EXEC master..xp_cmdshell @command
fetch next from mycursor into @EthMac, @cpeMac, @ipAddr
end
close mycursor
deallocate mycursor
end

The variable @numOfHosts is supposed to get incremented EVERYTIME the contents of the loop are executed, However it only gets incremented the FIRST time the contents of the loop are executed. So I end up @numofHosts being '1' through every iteration.

I just can't figure out why. Any ideas? Please help!
Nov 22 '06 #1
1 2903
AricC
1,892 Expert 1GB
Are you sure that it goes through the loop more than once?
Nov 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marco | last post by:
We can read this comment at php.net >jon >05-Nov-2003 10:06 >According to my tests, the "do...while" control structure actually seems to be ~40% faster than the "for" control structure. At...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
16
by: Joona I Palaste | last post by:
Reading Skybuck Flying's obvious troll message, I thought of how to properly do a for loop that would iterate over the complete range of an unsigned variable. As you all know, Skybuck's method...
10
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer and decared a Public Variable in the Class section. I assigned a value in the load section, and on a button I set it up to increment, but it always...
1
by: traceable1 | last post by:
SQL Server 2000 SP4 with AWE hotfix. Windows 2003 SP1. I have a stored procedure which is not working the way I think it should be. I have a CURSOR which has a variable in the WHERE clause: ...
5
by: Patrick | last post by:
I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
2
by: Arekkusu | last post by:
Hi, nice to meet everyone, im Arekkusu and im new to the forums. I have a slight problem..hopeing you guys and gals can help with. Its about trying to get a variable ($i), to increase by one every...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.