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 |
|
windex
Starting Member
3 Posts |
Posted - 2011-12-13 : 10:52:17
|
| So here's what I'm looking to do: I have one table that is a list of names:Tech, EmpIDChrisD, 123456JoeS, 123457TedL, 123458I'm creating a view that pulls data from a few different tables for one of the people above:Select stuff from tables where Tech='ChrisD'What I want to do is run the above Select statement for each Tech in the first table and Union all the results together.I started looking at cursors to do this, but then found a heap of info saying not to do it. What's the best way to do this? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-13 : 10:59:52
|
isnt it just of matter of joining them?SELECT t.Tech, t.EmpID,t1.Stuff,..FROM FirstTable tINNER JOIN tables t1ON t1.Tech = t.Tech ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sunnyleoneo
Starting Member
19 Posts |
Posted - 2011-12-13 : 12:35:23
|
| Visakh16 is correct.No need of cursor, actually you should avoid cursor as much as possible.SELECT stuffFROM tablesnameINNER JOIN tablewithtech ON tablesname.Tech = tablewithtech.Tech |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2011-12-13 : 13:41:49
|
Don't forget to mark sunny's answer as accepted http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
windex
Starting Member
3 Posts |
Posted - 2011-12-14 : 15:15:22
|
| Someone here showed me what I needed to do. I just needed to change my select statement to:Select stuff from tables where Tech IN (Select Techs From TechTable)I was thinking that each of the special calculations in 'stuff' was going to calculate differently than it did. |
 |
|
|
windex
Starting Member
3 Posts |
Posted - 2011-12-14 : 15:16:30
|
| Thanks for the replies either way. How do I mark someone's answer as accepted? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-12-14 : 17:15:03
|
SQLTeam doesn't mark answers that way. You can post a in thanks though. |
 |
|
|
|
|
|