0

I used this command in Sql Server to update a table using the maximum data in other table innerjoin

        UPDATE dbo.table2
        SET table2.LastGrantDate = max(table1.PlannedProjStartDate)
        from 
        table1 inner join table2
        on table2.Serial = table1.FundingEstablish

but it doesn't work

it workes only when I use it without the MAX() but

any way to solve this ??

1
  • 1
    But max command will always bring one value. Commented Jul 27, 2015 at 11:55

2 Answers 2

3

You need to use a subquery. Here is one way:

    UPDATE t2
    SET t2.LastGrantDate = t1.maxppsd
    from table2 t2 inner join
         (select FundingEstablish, max(PlannedProjStartDate) as maxppsd
          from table1
          group by FundingEstablish
         ) t1
         on t2.Serial = t1.FundingEstablish;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

UPDATE t2
        SET t2.LastGrantDate = t1.PlannedProjStartDate
        from 
        table1 as t1 inner join 
(select FundingEstablish,max(PlannedProjStartDate) as PlannedProjStartDate
from table2 group by FundingEstablish) as t2
        on t2.Serial = t1.FundingEstablish

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.