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 2000 Forums
 Transact-SQL (2000)
 Testing Transactions

Author  Topic 

ccrespo
Yak Posting Veteran

59 Posts

Posted - 2007-04-19 : 08:32:14
I have this query that updates a table that came with the software but I watned to test it first. Is there a way that instead of COMMIT TRAN at the end I could remove that and check to see how the results turn out then do a ROLLBACK? I'm not really sure how to test this query out. Thanks!

/* Insurance Balance Write-Off Update Query*/
BEGIN TRAN
SET NOCOUNT ON

DECLARE @PaymentMethodId int
DECLARE @VisitTransactionsId int
DECLARE @TransactionsId int
DECLARE @PayerName varchar(50)
DECLARE @BatchId int
DECLARE @AdjustmentTypeMId int
DECLARE @Amount money

SELECT @PayerName = ?PAYERNAME.TEXT?
SELECT @BatchId = ?BATCH.ITEMDATA.U?
SELECT @AdjustmentTypeMID = ?ADJUSTMENTTYPE.ITEMDATA.U?
SELECT @Amount = ?AMOUNT.TEXT.U?


DECLARE @Visit int
DECLARE @CarrierId int
DECLARE @PVPId int

DECLARE c_visit CURSOR STATIC FORWARD_ONLY LOCAL FOR
SELECT pv.PatientVisitId, pv.CurrentInsuranceCarriersId,pvp.patientvisitprocsid
FROM PatientProfile p
JOIN PatientVisit pv ON pv.PatientProfileId = p.PatientProfileId
JOIN InsuranceCarriers ic ON pv.CurrentInsuranceCarriersId = ic.InsuranceCarriersId
JOIN PatientVisitProcs pvp ON pv.patientvisitId = pvp.patientvisitid and pvp.voided is null
JOIN PatientVisitProcsAgg pvpa ON pvp.PatientVisitProcsId = pvpa.PatientVisitProcsId
AND pvpa.InsBalance > 0 AND pvpa.InsBalance < @amount AND pv.visit <?Date.Date?
AND --Filter on doctor
(
(?DOCTOR.ITEMDATA? IS NOT NULL AND pv.DoctorID IN (?DOCTOR.ITEMDATA.U?)) OR
(?DOCTOR.ITEMDATA? IS NULL)
)
AND --Filter on procedure
(
(?PROCEDURE.ITEMDATA? IS NOT NULL AND pvp.ProceduresId IN (?PROCEDURE.ITEMDATA.U?)) OR
(?PROCEDURE.ITEMDATA? IS NULL)
)
AND --Filter on Insurance Carrier
(
(?INSURANCECARRIER.ITEMDATA? IS NOT NULL AND pv.PrimaryInsuranceCarriersId IN (?INSURANCECARRIER.ITEMDATA.U?)) OR
(?INSURANCECARRIER.ITEMDATA? IS NULL)
)
AND --Filter on Insurance Group
(
(?INSURANCEGROUP.ITEMDATA? IS NOT NULL AND ic.InsuranceGroupId IN (?INSURANCEGROUP.ITEMDATA.U?)) OR
(?INSURANCEGROUP.ITEMDATA? IS NULL)
)

OPEN c_visit
FETCH NEXT FROM c_visit INTO @Visit, @CarrierId,@PVPId
WHILE (@@fetch_status<>-1)
BEGIN

INSERT PaymentMethod( Source, PayerName, PayerId, PayerType, BatchId, PaymentType,
Created, CreatedBy, LastModified, LastModifiedBy)
VALUES (2 /* Ins */, @PayerName, @CarrierId, 'Insurance', @BatchId, 6 /* Conveyance */,
GetDate(), dbo.GetLogonID(), GetDate(), dbo.GetLogonID())

SELECT @PaymentMethodId = (SELECT MAX(PaymentMethodId) FROM PaymentMethod WHERE CreatedBy = dbo.GetLogonID())

INSERT VisitTransactions( PatientVisitId, PaymentMethodId,
Payments, Adjustments, Transfers,
Created, CreatedBy, LastModified, LastModifiedBy)
VALUES ( @Visit, @PaymentMethodId,
0, 0, 0,
GetDate(), dbo.GetLogonID(), GetDate(), dbo.GetLogonID())

SELECT @VisitTransactionsId = @@IDENTITY

INSERT Transactions( VisitTransactionsId, Type, Action, ActionTypeMId, Name,
Created, CreatedBy, LastModified, LastModifiedBy)
VALUES ( @VisitTransactionsId, 'A', 'A', @AdjustmentTypeMId, 'Adjustment',
GetDate(), dbo.GetLogonID(), GetDate(), dbo.GetLogonID())

SELECT @TransactionsId = (SELECT MAX(TransactionsId) FROM Transactions WHERE CreatedBy = dbo.GetLogonID())

INSERT TransactionDistributions( PatientVisitProcsId, TransactionsId, Amount,
Created, CreatedBy, LastModified, LastModifiedBy)
SELECT pvp.PatientVisitProcsId, @TransactionsId, pvpa.InsBalance,
GetDate(), dbo.GetLogonID(), GetDate(), dbo.GetLogonID()
FROM PatientVisitProcs pvp
INNER JOIN PatientVisitProcsAgg pvpa ON pvp.PatientVisitProcsId = pvpa.PatientVisitProcsId
WHERE pvp.PatientVisitId = @Visit AND pvpa.InsBalance > 0
AND pvp.patientvisitprocsid = @pvpid
-- DONT NEED THIS HERE ->->-> FETCH NEXT FROM c_visit INTO @Visit, @CarrierId,@PVPId
--Set the correct bill status

EXEC SetBillStatus @Visit
Fetch next from c_visit INTO @Visit,@CarrierId,@PVPId
END

DEALLOCATE c_visit


COMMIT TRAN

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-19 : 08:44:07
Yes. Comment out the COMMIT TRAN statement. After doing the INSERTs, check the table for accuracy of the results and then just execute ROLLBACK TRAN command to discard the changes made.

Once you are done with this exercise and sure about the results, uncomment the final COMMIT TRAN statement.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2007-04-19 : 08:49:50
One method I tend to sometimes use that’s simple is for example on something like a simple update transaction

Select [col1] from [table] where [colid] = 2
GO
Set nocount on
begin tran

update [table]
set [col1] = [col1] + 10
where [colid] = 2
GO
Select [col1] from [table] where [colid] = 2

I would run them in batches for example in the above, run the select statement to get the previous result then the update happened in the transaction, then run a second select to retrieve the new result

then if needed because the transaction is still open you can then just type rollback transaction highlight the line & run and all will be rolled back

Very simple example and not really good for such large pieces of code but useful and quick I have found..
Go to Top of Page

ccrespo
Yak Posting Veteran

59 Posts

Posted - 2007-04-19 : 08:54:55
I haven't used cursors before but I'm not really sure. But can you open them like you could a temp table to check that data set thats in them?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-04 : 17:54:51
you don't open the cursors. you look in the table you're updating

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -