Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Join from same table?

Author  Topic 

boku
Starting Member

5 Posts

Posted - 2009-11-28 : 08:08:39
Hi,

I have a bit of an odd one ... here is a sample of what I am dealing with...

http://www.vbforums.com/attachment.php?attachmentid=74624&stc=1&d=1259384069

What I need to so somehow do is add the stklevel where the code is missing to the stk level where the item code = 'DUB' based on the item number...

So in the case of the sample ... for item number 01069103 ... the 24 where there is no code will be added to DUB where there is already 9 ... so DUB new stklevel will be 33

I will then go through and delete the rows where the code is missing, but I can do that afterwards ...

Has anyone got any tips please :)

Thank you

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-11-28 : 12:07:14
UPDATE s
SET stklevel = s.stklevel + t.sktlevel
from table s
inner join
table t on
s.itemno = t.itemno
where s.code = 'DUB' and t.code = ''

Jim



Everyday I learn something that somebody else already knew
Go to Top of Page

boku
Starting Member

5 Posts

Posted - 2009-11-28 : 21:02:28
Is this ok for the same table? Also where would I define the table, like this t = dbo.StkDepots, s = dbo.StkDepots

Go to Top of Page

boku
Starting Member

5 Posts

Posted - 2009-11-28 : 21:38:50
Ah .... duh ... just change "table" to the actual name ... my bad, sorry for DP
Go to Top of Page
   

- Advertisement -