I have the next code that I want to add in a sp to run in a job, what I mainly want to do is to get some records where an ID is equal to something
select distinct SMRR_ID from CR_Units where
I am supposed to get different IDs such as 2 and 4
Then I need to navigate through the results of the query and link it with another query that needs to run for each ID obtained
declare @To nvarchar(4000)
select @To = @To + b.EmailAddress + ';'
from CR_DistributionList a, SC_Users b
where a.UserID_ID = b.UserID_ID
and a.SMRR_ID = ?????
I think I can do it with a while but honestly I have never used it
Hope you can help me