I have a group of people who have taken a test. I can select their IDs with this query:
SELECT person_id
FROM tests
WHERE test_code = 1234
I'd like to pull these individuals' records from a demographics table, so I tried this subquery to do so:
SELECT *
FROM demographics d
WHERE d.person_id IN (
SELECT t.person_id
FROM tests t
WHERE t.test_code = 1234
)
... but I'm not getting any results. If I take a couple of the IDs from the (functional) subquery and hard-code them into the IN criteria:
SELECT *
FROM demographics d
WHERE d.person_id IN (01123, 58132)
... the query works. I've got to be missing something really fundamental here - do you know what it is?
Possible complicating factors: t.person_id is char13, d.person_id is varchar50. This is MS SQL Server 9.0.4035; I'm working in SQL Server Management Studio.
Thanks in advance for your help!