Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fails in SP, works in Query Analyzer 1

Status
Not open for further replies.

john0532

Programmer
Jul 2, 2002
27
0
0
US
I got an insert statement that works fine in the QA but when I put it in a Stored Procedure it doesn't work. I don't use Transact-SQL very much so I figure I'm missing something. Any tips would be appreciated.
Here's the code:

CREATE PROCEDURE [dbo].[migrate_data] AS
declare @days int
declare @vdays varchar(50)

declare days_cursor SCROLL CURSOR for
select setting from flags where type = 'TempJob days before purge'

open days_cursor

fetch absolute 1 from days_cursor into @vdays

set @days=CONVERT(int, @vdays)

close days_cursor
deallocate days_cursor
---------------------------------
begin transaction insert_records
---------------------------------
insert into archive
(
submitted,
model,
shop,
cc,
position,
job,
LineNumber,
ShimShop,
TotalShims,
TotalSize,
InProgress,
Completed,
MillUsedToCut,
Operator,
MaterialType
)
select
submitted,
model,
shop,
cc,
position,
job,
line,
ToShimShopID,
NumShims,
Area,
InProgress,
Completed,
Mill,
operator,
MaterialType
From TempJob
Where completed < (getdate()- @days) and status = 'completed'

----------------------------------
commit transaction insert_records
----------------------------------


 
When do you get the error?

On the Insert or the Create SP?

How are you executing the SP?
 
I don't get an error and nothing is inserted in the table. But the insert is performed when I run the same code with the query analyzer
 
It's hard for me to troubleshoot but one thing that might work is GO
deallocate days_cursor
---------------------------------
begin transaction insert_records
---------------------------------
GO
insert into archive
.... and at the end of the Insert
From TempJob
Where completed < (getdate()- @days) and status = 'completed'
GO
 
I made a stupid mistake. In the step of the scheduled job where I tell it to execute the stored procedure I mispelled the stored procedure name. Sorry to waste your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top