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 |
ann
Posting Yak Master
220 Posts |
Posted - 2008-04-17 : 11:15:13
|
My problem, I'm pretty sure, is the fact that I'm not looping through my records, and not sure how to go about doing this. I am trying to update 1 table based on the values of another table. Table 1:EmpName userNumberJohn Doe NullJane Smith NullBob Green NullTable 2:userName UserNumberJohn Doe 20Jane Smith 30Bob Green 40Desired Updated Table 1:EmpName userNumberJohn Doe 20Jane Smith 30Bob Green 40Code so far - updates all usernumber with 40: Declare @userID int Select @userID = userNumber from users where username in (Select RefEmp from Referral)So my code actually returns:Table 1:EmpName userNumberJohn Doe 40Jane Smith 40Bob Green 40Can anyone help?Thanks |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-17 : 11:20:14
|
why loopupdate Table1set usernumber = t2.usernumberfrom Table1 t1join Table2 t2on t2.username = t1.empname==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
ann
Posting Yak Master
220 Posts |
Posted - 2008-04-17 : 11:26:05
|
Thanks - that worked. As to why I didn't do it your way.. just didn't think to do it that way is all :) |
 |
|
|
|
|