I have an issue with one of my transaction. I set it up to print how many rows have been touched using @rowcount:
create proc Proc_Whole_Months_Work
@ProjectNum int,
@EmpId int,
@StartDate datetime,
@EndDate datetime
as
BEGIN TRANSACTION
declare @CurrentDate datetime
DECLARE @rowcount int
set @CurrentDate = @StartDate
while (@CurrentDate <= @EndDate)
begin
if (datepart(WEEKDAY, @CurrentDate) <=5 )--if it is a weekday
begin
insert into WorkHours(ProjectNum,EmpId,WorkDate,BeginTime,EndTime)values (@ProjectNum,@EmpId,@CurrentDate,'09:00:00','17:00:00')
end
set @CurrentDate =DATEADD(dd, 1, @CurrentDate)
end
SET @rowcount = @@ROWCOUNT
--print @rowcount
if(@rowcount = 0)
PRINT 'No rows Updated'
else
print 'Number Of Rows Updated:' + ' ' + str(@rowcount)
COMMIT TRANSACTION
go
For some reason that I don't seem to understand, the procedure prints "No rows updated" even when there are rows updated! Any Idea what I am doing wrong? Thanks so much!