I would like to query a table, and save the results into 1 field of a results table as below:
Table1:
StudentID FirstName LastName
JOHND John Doe
JANED Jane Doe
ROJERD Rojer Doe
JOHNNYJ Johnny Johnson
Table2:
SearchId Results
1 JOHND, JANED, ROJERD
Table 2 populated by 2 queries
SELECT StudentID FROM Table1 WHERE LastName = 'Doe'
i build the comma separated list from that query and then insert into table2
insert into Table2 (Results) VALUES (@StudentList)
Then I would like to select from the student table where student in results field like
SELECT * FROM Table1 WHERE StudentID IN (SELECT Results FROM Table2 WHERE SearchID = @SearchID)
I've tried adding single quotes to each side of each result, but that does not work either...
Table1:
StudentID FirstName LastName
JOHND John Doe
JANED Jane Doe
ROJERD Rojer Doe
JOHNNYJ Johnny Johnson
Table2:
SearchId Results
1 JOHND, JANED, ROJERD
Table 2 populated by 2 queries
SELECT StudentID FROM Table1 WHERE LastName = 'Doe'
i build the comma separated list from that query and then insert into table2
insert into Table2 (Results) VALUES (@StudentList)
Then I would like to select from the student table where student in results field like
SELECT * FROM Table1 WHERE StudentID IN (SELECT Results FROM Table2 WHERE SearchID = @SearchID)
I've tried adding single quotes to each side of each result, but that does not work either...
Comment