I'm really unsure if the title of this is what I am trying to say, but it's the closest I could come. What I want to do is take the initial results from a query and use them in a nested Select statement within an INSERT statement. Here is my example: Here is my initial query which gives me what I am looking for an works correctly;
SELECT Min(Inquirer.ID) as MinID, Max(Inquirer.ID) as MaxID,
Min(Inquirer.Program) as MinProg, Max(Inquirer.Program) as MaxProg,
COUNT(Inquirer.Name) AS NumOccurrences
FROM Inquirer
GROUP BY Inquirer.Name
HAVING ( COUNT(*) = 2 )
The results display like this;
MinID MaxID MinProg MaxProg NumOccurrences
27 81 Pavilion Appleton 2
I would like to use the MinID and MaxID values that I retrieve in a corresponding INSERT with a nested SELECT something like this;
Insert into Transfer(InquiryID_fk, ReferElsewhere, ReferMcLean, ReferExternal, ReferredFrom, TransferInquiryID_fk)
Values(SELECT Inquiry.ID from Inquiry
Where Inquiry.InquirerID_fk = MinID,'Yes',MaxProg,NULL,MinProg,
SELECT Inquiry.ID from Inquiry WHERE Inquiry.InquirerID_fk = MaxID)
And that is really it in a nutshell, not sure if it can be accomplished or how to accomplish it, would I have to make a temp table beforehand and loop through that to get the values? Any help is appreciated, thank you in advance,
NickG