Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Doing "Insert..Select" - not sure what is going on

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-19 : 08:32:46
I have following query snippet:

declare @JobNumber int
declare @JobNumber1 char(12)
declare @ItemNumber char(20)
declare @ItemNumber1 char(8)
declare @DateFrom datetime
declare @DateTo datetime
declare @JdeDateFrom int
declare @JdeDateTo int
set @JobNumber = 3505040
set @JobNumber1 = ' 3505040'
set @ItemNumber = '01010 '
set @ItemNumber1 = '01010 '
set @JdeDateFrom = 0
set @JdeDateTo = 0

create table #JDE_LaborHrsDetailTable
( jde_job_date datetime,
jde_cost_code char(15),
jde_equipment_id char(10),
jde_equipment_name char(20),
jde_employee_name char(15),
jde_employee_hours decimal(8,2),
jde_equipment_hours decimal(8,2)

)

insert into #JDE_LaborHrsDetailTable(jde_job_date, jde_cost_code, jde_equipment_id, jde_equipment_name,
jde_employee_name, jde_employee_hours, jde_equipment_hours)
Exec ('Call QGPL.get_labdet(?,?,?,?)', @JobNumber1, @ItemNumber1, @JdeDateFrom, @JdeDateTo) AT AS400SRV_MSDASQL1

select * from #JDE_LaborHrsDetailTable order by jde_job_date

drop table #JDE_LaborHrsDetailTable


I am doing some testing and using the query analyzer. When I manually cancel the query, the spid status is set to "Killed/Rollback". The rollback never finishes and is sitting out there for hours and days. We have to restart the server. Now If I try to run the same query again (and there is a rollback spid out there waiting to finish) the query never completes. When I run just the "Select" portion it completes fine. Can somebody tell me what is happening and if there is a way to avoid this, do I need to do something to my code?

doing sp_lock 90 returns

spid    dbid    obid            indld   type    mode    status  
90 12 0 0 DB S GRANT
90 2 174623665 0 TAB IX GRANT

heavymind
Posting Yak Master

115 Posts

Posted - 2009-03-19 : 09:47:22
how fine runs just
Exec ('Call QGPL.get_labdet(?,?,?,?)', @JobNumber1, @ItemNumber1, @JdeDateFrom, @JdeDateTo) AT AS400SRV_MSDASQL1
?

Thanks, Vadym
MCITP DBA 2005/2008
Chief DBA at http://www.db-staff.com
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-19 : 09:55:59
The "Exec" runs fast and fine.

The complete code I posted works fine. If I for some reason do a big test selection and need to cancel manually I have the problem I posted.

So when I kill the process I get:

SPID 90: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.

It never completes the rollback and it prevents me from running this code till we actually have restarted the server.
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-19 : 10:26:02
Could this be the case:

Since I am using a temp table and when I kill the query the temp table is automatically dropped. The roll back is trying to use a table that no longer exists.
Go to Top of Page
   

- Advertisement -