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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The worst instead of insert trigger that you have ever seen.

Status
Not open for further replies.

mercwrought

Programmer
Dec 2, 2004
176
US
Hi all been a while since i have posted. I have this trigger that is killing me. here is some back ground info.
Code:
CREATE TABLE #Png
(
	[RId] [int] NOT NULL,
	[RType] [char](3) NOT NULL,
	[SysCode] [varchar](7) NOT NULL,
	[Idnumber] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
	[TypeAPoints] [int] NOT NULL,
	[TypeBPoints] [decimal](13, 2) NOT NULL,
	[UsedTypeAPoints] [int] NOT NULL,
	[UsedTypeBPoints] [decimal](13, 2) NOT NULL,
)
RID,RType,SysCode are the key

this table recives points for a person
then eventualy the table recives an adjustment for a person
when i recive the adjustment i have to fill up the oldest points first
and keep filling till i run out of points.

I have to be able to make it black box so that everting takes place
perfirabley in the an insted of insert trigger.

I will know the adjustment because it will have an RType of 'ADJ'
the points will come as 'RSL'
the adjustemds can be negative for refunds.

I will at some point recive multiple records at the same time.

ok I think that is all of the back ground so here is what I have come up with and I feel dirty for having done this much.

I created a trigger that
1. Inserts all of the records into a temp table.
2. Adjust the placement of the points in the record based on if they are positive or negative and what Rtype they are.
3. (Please do not boo me) use a curser to get each row and then use a while loop to spend the points.

I know that there are much faster ways of ding this but I have no idea where to go and I refuse to continue working with this broken table till I get it fixed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top