I have the following in coldfusion:
<cfquery name="queryInRange" datasource="Database1" >
select STOCK
from CAR
WHERE (CAR_INV_DATE between '#dateStartDate#' and '#dateEndDate#')
</cfquery>
<cfoutput query="queryInRange">
<cfquery name="INSStocks" datasource="Database1" >
if not exists (select strStockNumber from Aggregates WHERE strStockNumber='#STOCK#')
BEGIN
insert into Aggregates (strStockNumber)
VALUES('#STOCK#')
END
</cfquery>
</cfoutput>
The idea here is to pull the field stock from one table, a vendor table, and make sure it has a record in the second table, which we then add some info to. I'm wondering, is there a way to do this in just sql, so there is cf loop?