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
 Transact-SQL (2000)
 Problem with strored procedure

Author  Topic 

stevo_3
Starting Member

20 Posts

Posted - 2006-01-04 : 11:00:49
Hello folks,

This is my code:
i got 2 tables
contact (id(key),.. external_id wich is the same as the officeid,...)
workitem (id(key), officeid, contact_id(wich is connected with the id(key) in contact...)

i want to lookup via the officeid the right id in contact and copy it into the workitem table (in contact_id)

This is what i've already tried to do:

declare @id int
if exists (SELECT id FROM contact WHERE EXISTS
(SELECT officeid FROM workitem WHERE external_id = officeid))

begin
update workitem
set contact_id=@id

end

PS. the query SELECT id FROM contact WHERE EXISTS
(SELECT officeid FROM workitem WHERE external_id = officeid) already works i have tested and it gives me the right value

but the rest isn't working at all
Thx


Steve

mdhingra01
Posting Yak Master

179 Posts

Posted - 2006-01-04 : 11:23:06
Why not just use an update statement
Update Workitem
Set contact_id=contact.officeid
from contact
WHERE EXISTS
(SELECT * FROM contact WHERE external_id = officeid))

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-05 : 01:43:12
After you executed your code, what does Select @@RowCount return?

Madhivanan

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

- Advertisement -