Fix in a Sql Statement for Sql Server 2008

I have some code. What I am trying to do is update a certain field to the max + 1

this is the code  that I have
 
update tblBNKrecon
set groupedpmtid = (MAX(GroupedPmtID)+1), newdesc = 'FEHBP' 
where groupedpmtid = 811209465 and [desc] = 'FEHBP HCCLAIMPMT'

Open in new window


the error I get is An aggregate may not appear in the set list of an UPDATE statement.
Thanks in advance
damixaAsked:
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.

Scott PletcherSenior DBACommented:
Please try this:

update tblBNKrecon
set groupedpmtid = (select MAX(GroupedPmtID) from tblBNKrecon) +1, newdesc = 'FEHBP'
where groupedpmtid = 811209465 and [desc] = 'FEHBP HCCLAIMPMT'
0
Kyle AbrahamsSenior .Net DeveloperCommented:
update tblBNKrecon
set groupedpmtid = (select MAX(GroupedPmtID) + 1 from tblBNKrecon), newdesc = 'FEHBP'
where groupedpmtid = 811209465 and [desc] = 'FEHBP HCCLAIMPMT'
0
damixaAuthor Commented:
Thanks guys,
Im also getting a warning
Warning: Null value is eliminated by an aggregate or other SET operation.

everything seems to be working though. Can you tell me what this means?
0
Kyle AbrahamsSenior .Net DeveloperCommented:
Essentially there is a GroupedPmtID that is null.  It doesn't know what to do with it, so it ignores it.  You can fix that by using the following:
update tblBNKrecon
set groupedpmtid = (select MAX(isnull(GroupedPmtID,0)) + 1 from tblBNKrecon), newdesc = 'FEHBP' 
where groupedpmtid = 811209465 and [desc] = 'FEHBP HCCLAIMPMT'

Open in new window

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
damixaAuthor Commented:
Thanks a ton
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.