Here’s what I’m trying do to in a single SQL Server procedure:
@ID1 int
select ID2 from TableA where ID1 = @ID1
(for each selected @ID2)
select * from TableB where ID2 = @ID2
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That can be done in a single statement:
But this means that there will be duplicates if more than one record in TABLE_A relates to a TABLE_B record. In that situation, use EXISTS rather than adding DISTINCT to the previous query:
The IN clause is equivalent, but EXISTS will be faster if there are duplicates: