I have 3 tables: ARTICLES (CAT_CODE, ART_CODE, ART_LABEL), BRANDS (BRA_CODE, BRA_LABEL) and ARTICLES_BRANDS (CAT_CODE, ART_CODE, MAR_CODE) which is used to associate an article from ARTICLES to a brand from BRANDS.

CAT_CODE is equal to 'I' since I am dealing here with computer hardware.

I have two articles (analog modem and DSL modem) that are very similar in the sense that they have the same associated brands. They have two different labels so they each have an entry in the ARTICLES table.

I already associated the first article with a serie of BRANDS in the ARTICLES_BRANDS table and I would like to assign the same brands to the second article in the ARTICLES_BRANDS table.

I started writing some code (see below) but I don't know how to make it work in a loop (I am doing this via SQL Query Analyzer under SQL 7.0):

****To find ART_CODE for the article 'analog modem' in ARTICLES****
SELECT ART_CODE AS CODE_MODEM_ANALOG FROM ARTICLES
WHERE ART_LABEL = 'analog modem'
AND CAT_CODE = 'I'

****To find ART_CODE for the article 'modem DSL' in ARTICLES****
SELECT ART_CODE AS CODE_MODEM_DSL FROM ARTICLES
WHERE ART_LABEL = 'modem DSL'
AND CAT_CODE = 'I'

****To find all the brand codes that are associated to 'analog modem'****
SELECT BRA_CODE AS CODE_BRAND FROM ARTICLES_BRANDS
INNER JOIN ARTICLES ON ARTICLES_BRANDS.ART_CODE = ARTICLES.ART_CODE
AND ARTICLES_BRANDS.CAT_CODE = ARTICLES.CAT_CODE
AND ARTICLES_BRANDS.CAT_CODE = 'I'
AND ARTICLES.ART_LIBELLE = 'analog modem'

****To insert into ARTICLES_BRANDS
INSERT INTO ARTICLES_MARQUES
(CAT_CODE, ART_CODE, BRA_CODE) VALUES ('I', CODE_MODEM_DSL, CODE_BRAND)

CODE_BRAND comes out as a column of values, how do I put all these values into a list and use this list to insert the corresponding associations for the DSL modem?

Can I do it from SQL Query Analyzer or do I have to use a ColdFusion page for example?

Thanks a lot.