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

Help with trigger...

Status
Not open for further replies.
Jul 25, 2000
33
0
0
US
Need to set a trigger so that when a new record is inserted the max value in column flx_objid will be taken and incrememnted by one for the new record. So far no luck. Here is what I am working with.

CREATE TRIGGER FLXTrans_ObjidCount
ON FLX_Transaction
FOR INSERT

AS

DECLARE @MaxCount int, @NewCount int, @OldCount int

SELECT @MaxCount = (Select Max(flx_objid) FROM FLX_Transaction)
SELECT @NewCount = @MaxCount + 1


IF @MaxCount is NULL
BEGIN
UPDATE FLX_Transaction SET flx_objid = 1
END
ELSE


UPDATE FLX_Transaction SET flx_objid = @NewCount

FROM

GO


Thanks in advance for your suggestions.


 
Why not use an Identity column? It would be much, much simpler.

Also, in your code:

[tt]UPDATE FLX_Transaction SET flx_objid = @NewCount

FROM

GO[/tt]

the "FROM" would be an error. Robert Bradley
Got extra money lying around? Visit:
 
Not quite sure what you mean by using an identity column. With the "from" removed from the code the trigger still will not fire.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top