Subquery returned more than 1 value

Hello,

I have a update query shown as below. But it's giving me a error message "Subquery returned more than 1 value".
UPDATE #TEMP_ACCOUNTING1
SET RETIREMENT_PLAN =
(SELECT
(SELECT MAX(Retirement_plan)  FROM #TEMP_ACCOUNTING1 Acc1
      WHERE  Acc1.PAY_PERIOD_ENDING_DATE < Acc2.PAY_PERIOD_ENDING_DATE
      and Acc1.ID= Acc2.ID)
FROM #TEMP_ACCOUNTING1 Acc2
WHERE Retirement_Plan IS NULL)

My data looks like...

ID                PAY_PERIOD_ENDING_DATE    Retirement_plan      Employee Name  
 1                 02/16/2010                                  k                            Tom
 1                 01/16/2010                                   k                             Tom
2                 02/16/2010                                   2                             King
2                 01/16/2010                                    2                             King

So basically my subquery does return more than one record for each "ID".
I want to update the "Retirement_plan " for all the PAY_PERIOD_ENDING_DATE of that "ID".

How can I achieve this task?
Please assist.

Thank you
angel7170Asked:
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.

Om PrakashCommented:
Try:
UPDATE Acc2
SET RETIREMENT_PLAN =
(
            SELECT
                  MAX(Retirement_plan)  
            FROM #TEMP_ACCOUNTING1 Acc1
                  WHERE  Acc1.PAY_PERIOD_ENDING_DATE < Acc2.PAY_PERIOD_ENDING_DATE
            and Acc1.ID= Acc2.ID
            )
FROM #TEMP_ACCOUNTING1 Acc2
WHERE Retirement_Plan IS NULL)
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
angel7170Author Commented:
It's giving me an error message

Invalid Object name 'ACC2'
0
Om PrakashCommented:
This works on my machine but it does not update anything for the data given by you
UPDATE Acc2
SET RETIREMENT_PLAN = 
(
            SELECT 
                  MAX(Retirement_plan)  
            FROM #TEMP_ACCOUNTING1 Acc1
                  WHERE  Acc1.PAY_PERIOD_ENDING_DATE < Acc2.PAY_PERIOD_ENDING_DATE 
            and Acc1.ID= Acc2.ID
            )
FROM #TEMP_ACCOUNTING1 Acc2 WHERE Retirement_Plan IS NULL

Open in new window

0
Om PrakashCommented:
I want to update the "Retirement_plan " for all the PAY_PERIOD_ENDING_DATE of that "ID".

update Retirement_plan to what value?
Also, you have selected   MAX(Retirement_plan), which contains text and numeric values.

what exactly needs to be updated and based on what condition?
0
angel7170Author Commented:
No comments
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 2005

From novice to tech pro — start learning today.