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 |
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-06 : 01:05:12
|
| Hi,I have two culumns A,B in Table1 and Column C, D in Table2I need to compare column combination of A and B with column C and DLike if 1- 10 is available in table2 then yes else No.Is this possible without looping.Please help!---------Table1-----------A - B1 - 102 - 113 - 124 - 135 - 146 - 15----------- Table2-----C - D1 - 102 - 112 - 122 - 133 - 143 - 154 - 134 - 194 - 204 - 215 - 155 - 166 - 15could someone help me here ASAP.Thanks,Pushp |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-06 : 03:46:19
|
You are not very clear.Please post the needed result in relation to your sample ASAP. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-06 : 05:02:46
|
| --------OUTPUT----------A - B Result 1 - 10 YES in table22 - 11 YES in table23 - 12 YES in table24 - 13 YES in table25 - 14 NO6 - 15 YES in table2output maybe like above or may be anything alse that represent if table1 combination is available in table2 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-07-06 : 05:31:55
|
[code]---------Table1-----------declare @table1 table(A varchar(10), B varchar(10))insert @table1select '1', '10' union allselect '2', '11' union allselect '3', '12' union allselect '4', '13' union allselect '5', '14' union allselect '6', '15'----------- Table2-----declare @table2 table(C varchar(10), D varchar(10))insert @table2select '1','10' union allselect '2','11' union allselect '2','12' union allselect '2','13' union allselect '3','14' union allselect '3','15' union allselect '4','13' union allselect '4','19' union allselect '4','20' union allselect '4','21' union allselect '5','15' union allselect '5','16' union allselect '6','15'selectt1.A,t1.B,case when t2.C is null then 'NO' else 'YES' end as Resultfrom @table1 as t1left join @table2 as t2 on t1.A = t2.C and t1.B = t2.D[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-07-06 : 07:18:49
|
| thanks webfred that worked for me!!thank you....... |
 |
|
|
|
|
|
|
|