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 |
|
rdev.theo
Starting Member
5 Posts |
Posted - 2011-07-12 : 15:01:39
|
| I am trying to get an out put where I would be comparing 2 fields across 2 tables based on a common field value, I need help to build a query where the result displays if 2 rows with same field value as true and if the comparison fails then I would need to to print as falseegTable 1 Table 2 Pimekey Sample1 Pimekey Sample2ADK12 Read2 ADK12 Read2ADK12 Read4 ADK12 Read3ADK14 Read1 ADK14 Read1ADK14 Read3 ADK14 Read2I need to displayPrimeKey Sample1 Sample2 ResultADK12 Read2 Read2 TRUEADK12 Read4 Read3 FALSEADK14 Read1 Read1 TRUEADK14 Read3 Read2 FALSEPlease suggestThanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-07-12 : 15:21:17
|
| SELECT t1.PrimeKey as t1PrimeKey ,t1.Sample1 as t1Sample1 ,t2.Sample2 as t2Sample2 ,case when t2.Sample2 = t1.Sample1 then 'true' else 'false' end as Resultfrom table1 t1 inner join table2 t2 on t1.primekey = t2.primekey JimEveryday I learn something that somebody else already knew |
 |
|
|
rdev.theo
Starting Member
5 Posts |
Posted - 2011-07-12 : 17:50:06
|
| Thanks JimRam Dev |
 |
|
|
rdev.theo
Starting Member
5 Posts |
Posted - 2011-07-12 : 17:54:02
|
| I just had one more question, what if table 1 was to be derived from joining another 2 different tables with a common field between them?Ram Dev |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-07-12 : 18:18:26
|
| replace table1 with your derived query and all should be finefrom (derived table)t1 inner join table2 t2 on t1.primekey = t2.primekey JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|