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 - 2006-07-31 : 15:24:30
|
| I have to retreive a branchmanager name from a table. In order to do this I go through this:Table1 usersuserNumber (int), username(varchar), branchNumber(int)....table2 branchesbranchNumber(int), branchName (varchar), branchManger (int)...1 - get the branchNumber for user from users tableSelect branchNumberFrom usersWhere userName = 'Ann LastName'2 - get the branchmangerID from branches (this is the userNumber on the users table)SELECT BranchManagerIDFROM BranchesWhere BranchNumber = branchNumberResult from #13.Select userNameFrom usersWhere userNumber = branchNumberResult from #2Is there a way to do combine these select statements?Thanks |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-07-31 : 15:51:37
|
Select Manager = C.userNameFrom users AInner Join Branches BOn A.BranchNumber = B.BranchNumberInner Join users COn B.BranchManagerID = C.userNumberWhere userName = 'Ann LastName'Corey Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..." |
 |
|
|
ann
Posting Yak Master
220 Posts |
Posted - 2006-07-31 : 16:02:43
|
| I KNEW there was a better way!Thanks so much - it works great :)As you can tell from my attempt, I'm not very well versed in sql |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|