Q:

How to check if the result of a query is equal to one of the results from another query in SQL?

My target query returns either 1s or 0s depending on whether certain conditions are met:
SELECT TOP 1
ISNUMERIC(LEFT(Attachment, 4)) as Column1,
ISNUMERIC(SUBSTRING(Attachment, 5, 4)) as Column2
--Column3 to be included
FROM Table1

As of now, the results are:
Column1|Column2
1       0

I want to include Column3 into my target query. The result I want is either a 1 or a 0 like in the previous two columns. I want to use the following query to determine the result:
SELECT
Description
FROM Table2 
WHERE Status = 1

The results are as follows:
AA
BB
CC

I want to check whether SELECT SUBSTRING(Attachment, 9, 2) FROM Table1 = one of the results FROM Table2. If a match is found I want a 1, if not a 0. I probably need to use the CASE structure, but I'm not sure.

A:

You can use case and exists or in:
SELECT TOP 1 ISNUMERIC(LEFT(t1.Attachment, 4)) as Column1,
       ISNUMERIC(SUBSTRING(t1.Attachment, 5, 4)) as Column2,
       (CASE WHEN SUBSTRING(Attachment, 9, 2) IN (SELECT Description FROM Table2 WHERE Status = 1)
             THEN 1 ELSE 0
        END) as Column3 
FROM Table1 t1;

