0
votes

I have an excel sheet like this:

column1     column2
a            b
b            w
c            a
d            c
e            z
f            k
g            t
h            y
i            j
j            d
k            e
l            f

and I want to match the column1 first value a with each and every value of column2. If value is found I want to show some message in next column like Found or highlight the value itself and then value b should be found in column2 and so on.

Objective:

Actually I have two tables in sql with multiple columns and those tables have some common columns also.I just want to find out the matching column names. If someone has some other way also,Please let me know. Thanks in advance.

1
need to create a trigger on the original table, so i need to extract the common column names in both the tables.Mogli
you need the solution in Excel or SQLvanathaiyan

1 Answers

0
votes

Something like this should work in SQL Server

;with cte as
(
SELECT *
FROM   (VALUES ('a','b'),
               ('b','w'),
               ('c','a'),
               ('d','c'),
               ('e','z'),
               ('f','k'),
               ('g','t'),
               ('h','y'),
               ('i','j'),
               ('j','d'),
               ('k','e'),
               ('l','f') ) tc (column1, column2) 
)
SELECT column1,
       CASE
         WHEN EXISTS (SELECT 1
                      FROM   cte b
                      WHERE  a.column1 = b.column2) THEN 'Found'
         ELSE 'Not Found'
       END AS Identifier
FROM   cte a 

Result:

+--------+--------------+
|column1 |  Identifier  |
+--------+--------------+
| a      | Found        |
| b      | Found        |
| c      | Found        |
| d      | Found        |
| e      | Found        |
| f      | Found        |
| g      | Not Found    |
| h      | Not Found    |
| i      | Not Found    |
| j      | Found        |
| k      | Found        |
| l      | Not Found    |
+--------+--------------+