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 |
jportnoy
Starting Member
7 Posts |
Posted - 2006-08-14 : 12:12:18
|
I have the following setup:Table A______________Table BName...Value____NameID____ValueName1...x_________x_______"John"Name2...y_________y_______"Frank"I need to create a join that would allow me to create a view matching up the value of table A with the ID of table B. Can somebody send me a code snippet on how I would do this with a join? Thank you. |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-14 : 12:16:43
|
not sure what you want but it looks likeselect *from TableA ajoin TableB bon a.Value = b.NameID==========================================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. |
 |
|
jportnoy
Starting Member
7 Posts |
Posted - 2006-08-14 : 12:21:55
|
Alright, I wasn't nearly clear enough. Table A: contains a field "Name" and another field "Name2". The data types for these fields are ints. Table B: contains two fields: "NameID" and "ActualName". The fields "Name" and "Name2" from Table A need to match up with the "ActualName" from Table B. I need to create a view that has fields "Name1" and "Name2" that contain the value of the "ActualName" field in Table B. Sorry for the lack of clarity in the last post. |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-14 : 12:54:29
|
select Name1 = b1.ActualName ,Name2 = b2.ActualNamefrom TableA ajoin TableB b1on a.Name = b1.NameIDjoin TableB b2on a.Name2= b2.NameID==========================================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. |
 |
|
jportnoy
Starting Member
7 Posts |
Posted - 2006-08-14 : 13:53:22
|
Is there a way to get one record back, instead of the 2 that are currently being returned? (They're identical records with the actualName field changed) |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-14 : 14:08:54
|
It will bring back one row for each row in TableA.Maybe you have the reverse entry in TableA?if soselect Name1 = b1.ActualName ,Name2 = b2.ActualNamefrom TableA ajoin TableB b1on a.Name = b1.NameIDjoin TableB b2on a.Name2= b2.NameIDwhere a.Name <= a.Name2==========================================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. |
 |
|
jportnoy
Starting Member
7 Posts |
Posted - 2006-08-14 : 15:17:24
|
Awesome. Thanks a bunch man. |
 |
|
|
|
|