SQL Syntax to prevent duplicates

Let's say I have a table with the struture of
JOBNUMBER, TRNSNMBR,SEQNUMBR,AMOUNT and the primary key is based on
JOBNUMBER, TRNSNMBR,SEQNUMBR

I want to be able to duplicate the record and want to use the SEQNUMBR to avoid duplicates.

INSERT INTO MYTABLE
SELECT JOBNUMBER, TRNSNMBR,SEQNUMBR
FROM MYTABLE
WHERE JOBNUMBER='MYJOB' AND TRNSNMBR='MYTRXNMBR' AND SEQNUMBR='MYSEQ'

Will result in a duplicate record. What is the cleanest, most efficient way to structure this insert statement so that it will find the highest value for SEQNUMBR and then increment it by 1?  The possibility is there that users will want to duplicate this same record more than once so it cannot just be add 1, it needs to find the highest value and then increment by 1. I am not allowed to modify the structure of the underlying table.
LVL 1
rwheeler23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
SELECT JOBNUMBER, TRNSNMBR,SEQNUMBR
FROM MYTABLE
WHERE JOBNUMBER='MYJOB' AND TRNSNMBR='MYTRXNMBR' AND SEQNUMBR=MAX('MYSEQ')
0
rwheeler23Author Commented:
I am getting a message about the subquery missing a Having clause.
0
QuinnDexCommented:
declare @SEQplus1 int
set @SEQplus1 = (select max(SEQNUMBR) + 1 FROM MYTABLE)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwheeler23Author Commented:
Perfect, brought the two of these together and it works like a charm. Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.