I've either found a bug or I've gone insane. I have a select into statement that runs outside a stored proc but creates an open transaction that hangs within the stored proc. I'm on SQL 2000 sp3. It also runs if I put the statement into a variable and run it as EXEC(@sql). Inside the proc it just hangs like it's waiting on a commit. There is a select into statement that I've taken out for this post and it runs inside the proc just fine, but when it parses to this one it just sits there.
Here's the code, any suggestions?
procedure dbo.jc_HistoryTest
@AccountNumber int,
@DateFrom datetime,
@DateTo datetime,
@UserId VARCHAR(50),
@TagId int
as
DECLARE
@DBFail INT,
@DBSuccess INT,
@MaxTagId INT,
@MaxUserId VARCHAR(50)
SELECT
@DBFail = -1 ,
@DBSuccess = 0
/* Create the dynamic SQL substitutes */
IF @DateFrom IS NULL
SELECT @DateFrom = '01/01/1900'
IF @DateTo IS NULL
SELECT @DateTo = '01/01/2050'
IF @TagId IS NULL
BEGIN
SELECT @MaxTagId = MAX(fk_Tag_Id)
FROM TAG_HISTORY
SET @TagId = 0
END
ELSE
SELECT @MaxTagId = @TagId
IF @UserId IS NULL
BEGIN
SELECT @MaxUserId = 'ZZZZZZZZ'
SELECT @UserId = 'a'
END
ELSE
SELECT @MaxUserId = @UserId
PRINT 'Start Select Section'
SELECT T.Transaction_ID,
T.POSTING_DATE_TIME,
T.TRANS_DATE_TIME,
T.TRANS_AMT,
T.END_BALANCE,
T.FK_TRANSACTION_TYPE,
T.FK_ACCOUNT_STATUS,
T.FK_APID,
TT.RPTD_CLASS_ID,
TT.PREV_DATE_TIME,
TT.FK_PLAZA_ID,
TT.FK_PREV_PLAZA_ID,
TT.TOLL_AMT_EXPECTED,
TT.FK_REASON_CODE,
TT.FK_TAG_ID,
TT.FK_LANE_TAG_STATUS
INTO #temp_tag
FROM trans T,
TAG_TRANS TT
WHERE T.fk_ACCOUNT_NUMBER = @AccountNumber
AND T.TRANS_DATE_TIME >= @DateFrom
AND T.TRANS_DATE_TIME <= (@DateTo + ' 23:59:59')
AND T.TRANSACTION_ID = TT.FK_TRANSACTION_ID
AND TT.Fk_TAG_ID >= @TagId
AND TT.Fk_TAG_ID <= @MaxTagId
ORDER BY T.TRANSACTION_ID
The parameters are:
N'2232', NULL, NULL, NULL, NULL
Here's the code, any suggestions?
procedure dbo.jc_HistoryTest
@AccountNumber int,
@DateFrom datetime,
@DateTo datetime,
@UserId VARCHAR(50),
@TagId int
as
DECLARE
@DBFail INT,
@DBSuccess INT,
@MaxTagId INT,
@MaxUserId VARCHAR(50)
SELECT
@DBFail = -1 ,
@DBSuccess = 0
/* Create the dynamic SQL substitutes */
IF @DateFrom IS NULL
SELECT @DateFrom = '01/01/1900'
IF @DateTo IS NULL
SELECT @DateTo = '01/01/2050'
IF @TagId IS NULL
BEGIN
SELECT @MaxTagId = MAX(fk_Tag_Id)
FROM TAG_HISTORY
SET @TagId = 0
END
ELSE
SELECT @MaxTagId = @TagId
IF @UserId IS NULL
BEGIN
SELECT @MaxUserId = 'ZZZZZZZZ'
SELECT @UserId = 'a'
END
ELSE
SELECT @MaxUserId = @UserId
PRINT 'Start Select Section'
SELECT T.Transaction_ID,
T.POSTING_DATE_TIME,
T.TRANS_DATE_TIME,
T.TRANS_AMT,
T.END_BALANCE,
T.FK_TRANSACTION_TYPE,
T.FK_ACCOUNT_STATUS,
T.FK_APID,
TT.RPTD_CLASS_ID,
TT.PREV_DATE_TIME,
TT.FK_PLAZA_ID,
TT.FK_PREV_PLAZA_ID,
TT.TOLL_AMT_EXPECTED,
TT.FK_REASON_CODE,
TT.FK_TAG_ID,
TT.FK_LANE_TAG_STATUS
INTO #temp_tag
FROM trans T,
TAG_TRANS TT
WHERE T.fk_ACCOUNT_NUMBER = @AccountNumber
AND T.TRANS_DATE_TIME >= @DateFrom
AND T.TRANS_DATE_TIME <= (@DateTo + ' 23:59:59')
AND T.TRANSACTION_ID = TT.FK_TRANSACTION_ID
AND TT.Fk_TAG_ID >= @TagId
AND TT.Fk_TAG_ID <= @MaxTagId
ORDER BY T.TRANSACTION_ID
The parameters are:
N'2232', NULL, NULL, NULL, NULL