Well that was close. There were still a few issues but I was able to muddle my way through. (the insert issue was the very last one on the list had too many NULLs at the end.
Now that I could actually see what was going on this whole procedure can be made about a million times more simple.
Basically all you were doing was getting all the towns, then looping through them one at a time and updating the PermitsCountdown to the value in Permits where the PermitsCountdown <> Permits. You can do this in a single update statement with no need at all for a cursor.
Unless I am missing something I think you could change your entire sp_ResetPermitsCountdown proc to be as simple as:
CREATE PROCEDURE [survey].[sp_ResetPermitsCountdown] AS
update [survey].[FirewoodTowns]
set PermitsCountdown = Permits
where PermitsCountdown <> Permits
Also, you really should not use the "sp_" prefix for your procedure names. SQL server will first think is a system stored proc.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/