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 2000 Forums
 SQL Server Development (2000)
 Update cell with other cell info

Author  Topic 

misterzr
Starting Member

49 Posts

Posted - 2006-01-12 : 09:33:43
I am trying to update a table that is missing some Invoice numbers. I need to base the invoice number on another invoice number from the same table based on a cell for the same invoice group

Table is #holding
Invoice column is SDDOC
Group column is SDPRGR

So if SDDOC is 0 then I need to update a value to it from SDDOC that has the same group (SDPRGR)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-12 : 09:37:15
Is this?

Update #holding
set SDDOC = SDPRGR
where SDDOC =0

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

misterzr
Starting Member

49 Posts

Posted - 2006-01-12 : 09:49:33
Not quite, I need SDDOC = SDDOC where it is 0 and based on SDPRGR = SDPRGR
Go to Top of Page

misterzr
Starting Member

49 Posts

Posted - 2006-01-12 : 10:04:09
Maybe this will help clarify what I am trying to do

SDPRGR	         SDDOC

PHARM 1293931
PHARM 1293931
OTC 0
OTC 0
PHARM 1293931
HH 1293939
OTC 1293938

Need to set the ZEROS to 1293938 to match the same as the SDDOC in the same group (OTC)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-12 : 20:59:47

create table #holding
(
SDPRGR varchar(10),
SDDOC int
)

insert into #holding
select 'PHARM', 1293931 union all
select 'PHARM', 1293931 union all
select 'OTC', 0 union all
select 'OTC', 0 union all
select 'PHARM', 1293931 union all
select 'HH', 1293939 union all
select 'OTC', 1293938

update h
set SDDOC = (select top 1 SDDOC from #holding x where x.SDPRGR = h.SDPRGR and SDDOC <> 0)
from #holding h
where SDDOC = 0

select * from #holding



-----------------
'KH'

if you can't beat them, have someone else to beat them
Go to Top of Page
   

- Advertisement -