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.
| 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 intif exists (SELECT id FROM contact WHERE EXISTS(SELECT officeid FROM workitem WHERE external_id = officeid))begin update workitem set contact_id=@idendPS. 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 ThxSteve |
|
|
mdhingra01
Posting Yak Master
179 Posts |
Posted - 2006-01-04 : 11:23:06
|
| Why not just use an update statementUpdate WorkitemSet contact_id=contact.officeidfrom contactWHERE EXISTS(SELECT * FROM contact WHERE external_id = officeid)) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-05 : 01:43:12
|
| After you executed your code, what does Select @@RowCount return?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|