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 |
Brittney10
Posting Yak Master
154 Posts |
Posted - 2012-01-19 : 09:23:58
|
I have 4 fields: Primary_Id, User_Id, Admin_Id, and Admin_Name. I need to be able to update the Admin_ID with the Primary_ID if the User_ID and Mgr_Name match (i.e find the Admin_ID for a particular User_ID). For example: Primary_ID............User_ID..............Admin_Id........Admin_Name1....................John.Doe..............NULL............Jane.Doe2....................Jane.Doe..............NULL............Joe.Doe3....................James.Doe.............NULL............John.Doe4....................Joe.Doe...............NULL............Jane.DoeThis would become: Primary_ID............User_ID..............Admin_Id.........Admin_Name1....................John.Doe...............2...............Jane.Doe2....................Jane.Doe...............4...............Joe.Doe3....................James.Doe..............1.............. John.Doe4....................Joe.Doe................2...............Jane.Doe |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-19 : 09:27:37
|
Test it:update t1set Admin_Id = t2.Primary_Idfrom YourTable t1join YourTable t2 on t1.Admin_Name = t2.User_Id No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2012-01-19 : 09:59:07
|
quote: Originally posted by webfred Test it:update t1set Admin_Id = t2.Primary_Idfrom YourTable t1join YourTable t2 on t1.Admin_Name = t2.User_Id No, you're never too old to Yak'n'Roll if you're too young to die.
Yes that work perfectly! Thanks! |
 |
|
|
|
|