When using the T-SQL debugger the sp appears to be working, returning the new record number from a SELECT statement. However 98% of the time the Enterprise Manager shows no new records in the table. It's the fact that it works occasionally that has me stumped. The Profiler says the sp is doing 300+ reads and 0 writes.
SQL Server 2000
here's the sp:
CREATE PROCEDURE [dbo].[spTestCopyJob]
AS
declare @newrecnum int
declare @oldrecnum int
declare @jobid int
declare @asite varchar(50)
declare @model varchar(50)
declare @shop varchar(50)
declare @cc varchar(50)
declare @position varchar(50)
declare @job varchar(50)
declare @RetVal int
declare @counter int
declare @LML datetime
set @jobid = 34631
set @asite = 'EVERETT'
set @model = '767'
set @shop = 'TW330'
set @cc = '201'
set @position = '06'
set @job = '12e312r_copy1'
select @LML = Lastmodifiedlayout from jobs where [job id] = @jobid
BEGIN TRANSACTION T1
insert into [testspcopyjob] (site, model, shop, cc, position, job, lastmodifiedlayout)
values(@asite, @model, @shop, @cc, @position, @job, @LML)
COMMIT TRANSACTION T1
--insert into jobs (site, model, shop, cc, position, job, Lastmodifiedlayout)
select site, model, shop, cc, position, @job, lastmodifiedlayout
from [testspcopyjob]
where [job id] = @jobid
select @newrecnum=[job id]
from [testspcopyjob]
where site = @asite and model = @model and shop = @shop and cc = @cc and position = @position and job = @job
select @counter = count(*)
from [testspcopyjob]
where site = @asite and model = @model and shop = @shop and cc = @cc and position = @position and job = @job
print 'counter='
print @counter
set @RetVal = @newrecnum
GO
SQL Server 2000
here's the sp:
CREATE PROCEDURE [dbo].[spTestCopyJob]
AS
declare @newrecnum int
declare @oldrecnum int
declare @jobid int
declare @asite varchar(50)
declare @model varchar(50)
declare @shop varchar(50)
declare @cc varchar(50)
declare @position varchar(50)
declare @job varchar(50)
declare @RetVal int
declare @counter int
declare @LML datetime
set @jobid = 34631
set @asite = 'EVERETT'
set @model = '767'
set @shop = 'TW330'
set @cc = '201'
set @position = '06'
set @job = '12e312r_copy1'
select @LML = Lastmodifiedlayout from jobs where [job id] = @jobid
BEGIN TRANSACTION T1
insert into [testspcopyjob] (site, model, shop, cc, position, job, lastmodifiedlayout)
values(@asite, @model, @shop, @cc, @position, @job, @LML)
COMMIT TRANSACTION T1
--insert into jobs (site, model, shop, cc, position, job, Lastmodifiedlayout)
select site, model, shop, cc, position, @job, lastmodifiedlayout
from [testspcopyjob]
where [job id] = @jobid
select @newrecnum=[job id]
from [testspcopyjob]
where site = @asite and model = @model and shop = @shop and cc = @cc and position = @position and job = @job
select @counter = count(*)
from [testspcopyjob]
where site = @asite and model = @model and shop = @shop and cc = @cc and position = @position and job = @job
print 'counter='
print @counter
set @RetVal = @newrecnum
GO