Hi,
I inherited a stored procedure which works in an ADODB environment. When run
in an ODBC environment, it fails with a SQL_NO_DATA error at SQL_Execut(). I get an
"Invalid object name '#T' " error in the Query Analyser along with the data. It seems
that ADODB ignores the error and ODBC errors out? Hacking the code line by line
until the "Invalid ..." error goes away yields a happy SQL_Execute (wrong data
because of hack though). So - can anyone see the problem in this code, or can
anyone propose a rewrite so as to eliminate the temp table?
CREATE Procedure Broken
(
@nTop INT,
@OldStatus INT,
@OldOwner VARCHAR(100),
@TimeIndicator DECIMAL(15,7),
@NewStatus INT,
@NewOwner VARCHAR(100),
@nMode INT
)
As
--what does this do?
SELECT A.ID INTO #T FROM TOBJ A WHERE 1 = 2
--identify records status and owner, and record their ids in a temp table
INSERT INTO #T
SELECT TOP @nTop ID
FROM TDATA WHERE STATUS = @OldStatus
AND OWNER = @OldOwner
ORDER by TIMEORDER
--update those records status and owner fields (can't reselect now!)
UPDATE TDATA SET STATUS = @NewStatus, OWNER = @NewOwner FROM #T
WHERE TDATA.ID = #T.ID
--now, using the same set of ids, select and return OBs from the OBJ table
SELECT OB FROM TOBJ, #T
WHERE TOBJ.ID = #T.ID
DROP TABLE #T
Any help is greatly appreciated!!!
I inherited a stored procedure which works in an ADODB environment. When run
in an ODBC environment, it fails with a SQL_NO_DATA error at SQL_Execut(). I get an
"Invalid object name '#T' " error in the Query Analyser along with the data. It seems
that ADODB ignores the error and ODBC errors out? Hacking the code line by line
until the "Invalid ..." error goes away yields a happy SQL_Execute (wrong data
because of hack though). So - can anyone see the problem in this code, or can
anyone propose a rewrite so as to eliminate the temp table?
CREATE Procedure Broken
(
@nTop INT,
@OldStatus INT,
@OldOwner VARCHAR(100),
@TimeIndicator DECIMAL(15,7),
@NewStatus INT,
@NewOwner VARCHAR(100),
@nMode INT
)
As
--what does this do?
SELECT A.ID INTO #T FROM TOBJ A WHERE 1 = 2
--identify records status and owner, and record their ids in a temp table
INSERT INTO #T
SELECT TOP @nTop ID
FROM TDATA WHERE STATUS = @OldStatus
AND OWNER = @OldOwner
ORDER by TIMEORDER
--update those records status and owner fields (can't reselect now!)
UPDATE TDATA SET STATUS = @NewStatus, OWNER = @NewOwner FROM #T
WHERE TDATA.ID = #T.ID
--now, using the same set of ids, select and return OBs from the OBJ table
SELECT OB FROM TOBJ, #T
WHERE TOBJ.ID = #T.ID
DROP TABLE #T
Any help is greatly appreciated!!!