Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update table with left join
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01526632
Message ID:
01526719
Views:
25
>>>>>>>I was so used to flip that around in VFP!
>>>>>>
>>>>>>Hmm, never tried flipping it around in VFP either. BTW, pay attention to other changes I made in your query.
>>>>>
>>>>>Great, it's working good, and fast. Problem was that originally I had a scan doing the updates in Business objects and posting one by one, and that took too long, so I had to do a direct query to update all at once.
>>>>
>>>>I am not sure why do you need inner join here. Why not just:
>>>>
>>>>UPDATE EmpItems ;
>>>>SET itOnPosted = 1, ;
>>>>itBalAmt = HistItems.itBalNew + HistItems.itPostCalc;
>>>>FROM HistItems where HistItems.eiKey = EmpItems.eiKey and HistItems.DelFlag = 0 
>>>>
>>>
>>>This is not going to work. HistItems is a different table so you must join with it.
>>
>>You have any working strand alone example that supports it? Then show it to me.
>
>Intrerestingly - I realized it was a disguised JOIN (using WHERE clause). It is hard to understand (IMHO), but it works:
>
>
>use tempdb 
>
>create  table EmpItems(itOnPosted int, itBalAmt int, eiKey int primary key)
>
>insert into EmpItems (eiKey) values (1),(2),(3)
>
>declare @HistItems table (itBalNew int, itPostCalc int, DelFlag bit default 0, eiKey int)
>
>insert into @HistItems (itBalNew, itPostCalc, eiKey)
>
>values (10, 20, 1), (15, 14, 2), (25, 12, 3)   
>
>UPDATE EmpItems 
>SET itOnPosted = 1, 
>itBalAmt = HistItems.itBalNew + HistItems.itPostCalc
>FROM @HistItems HistItems where HistItems.eiKey = EmpItems.eiKey and HistItems.DelFlag = 0 
>
>select * from EmpItems
Yes, UPDATE works very similar to select statements where inner join is equivalent to select statement like select ... from table1,table2 where table1.field1=table2.field2
Previous
Reply
Map
View

Click here to load this message in the networking platform