Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Join statement
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01265876
Message ID:
01266022
Views:
11
>Thank you...one small change and I got what I needed.
>
>Thanks again for your help.
>Daniel
>
>
>update a
>set a.nchange = 1
>from bdgt_m a
>     join (SELECT DISTINCT bdgt_m_deleted.cacctid, bud_new, bdgt_m_deleted.ddeleted
>                  FROM bdgt_m_deleted
>                  INNER JOIN (SELECT cacctid, MAX(ddeleted) AS ddeleted
>                                     FROM bdgt_m_deleted GROUP BY cacctid) Tbl1
>           ON  bdgt_m_deleted.ddeleted = Tbl1.ddeleted) B
>on a.cacctid = b.cacctid
>where a.bud_new <> b.bud_new
>
No, not good. The change you made changes the statement completely and you will never be sure about the result. Because you JOIN table ONLY by Date.
Try:
update a
set a.nchange = 1
from bdgt_m a
     join (SELECT DISTINCT bdgt_m_deleted.cacctid, bud_new, bdgt_m_deleted.ddeleted
                  FROM bdgt_m_deleted
                  INNER JOIN (SELECT cacctid, MAX(ddeleted) AS ddeleted
                                     FROM bdgt_m_deleted GROUP BY cacctid) Tbl1
           ON bdgt_m_deleted.cacctid  = Tbl1.cacctid AND
              bdgt_m_deleted.ddeleted = Tbl1.ddeleted) B
on a.cacctid = b.cacctid
where a.bud_new <> b.bud_new
That way you will get MAX() date for every cacctid.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform