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 |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2006-04-14 : 08:34:48
|
| Please help with writing queryI have 2 tables:Table1:ID Description1 name12 name23 name3...Table2:SiD ID123 1456 2789 myname852 yournameif description exisits in table1 get description from table1 in all other cases get ID from table2 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-14 : 08:37:18
|
| Post your expected dataMadhivananFailing to plan is Planning to fail |
 |
|
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2006-04-14 : 08:53:16
|
| Name1name2mynameyourname |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-14 : 09:19:45
|
Why did you store id and description in the same column in table2?You can try something like thisselect Description from table1 t1 left join table2 t2 on t1.id=T2.id where t2.sid is not nullunion allselect t2.id from table1 t1 right join table2 t2 on t1.id=T2.id where t1.id is null MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|