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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-11-06 : 08:21:47
|
| MikeC writes "This sounds like a simple question, but I can't find the answer anywhere. I have two tables 1) a list of people, and 2) a list of selections for each person - selecting others from the original list of people. I need a query (or view) to show the entire list of people, but have a field indicating if that a person in the list was selected by a chosen person. I have used a 'right outer join' to show all people from the list, but when I select the criteria for the chosen person, it will show only those that match.table1idfirstnamelastnametable2id_chosenid_selectedexample datatable11, george washington2, john adams3, thomas jeffersontable21, 11, 22, 12, 3In this example, George Washington has selected himself and John Adams. John Adams has selected Washington and Jefferson. In need a query to produce this when George Washington is view his list:1, George Washington, Selected2, John Adams, Selected3, Thomas Jefferson, Not SelectedThanks" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-11-06 : 08:32:22
|
| select t1.firstname, t1.lastname, case when t2.id_selected is null then 'Not ' else '' end + 'Selected'from table1 t1left outer join table2 t2on t2.id_selected = t1.idand t2.id_chosen = @userid==========================================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. |
 |
|
|
|
|
|
|
|