Just a quick question for the gurus in the forum...
I have 1 parent table and 3 child tables that are all related by an identity field in the parent table (sequence_number). I have the following statements in my stored procedure
INSERT INTO PRODUCT (NAME,
NUMBER,
MAKE,
TYPE,
MODEL)
SELECT DISTINCT XML_PRODUCT.NAME,
XML_PRODUCT.NUMBER,
XML_PRODUCT.MAKE,
XML_PRODUCT.TYPE,
XML_PRODUCT.MODEL
FROM XML_PRODUCT
This insert works great on the parent table, but when it is inserted, the identity field for each record inserted is populated with the next available number. My question is, how can I get the identity number from each record inserted to insert into the child tables like this ...
INSERT INTO PRODUCT_DESCRIPTION (SEQUENCE_NUMBER, /*IDENTITY FROM PARENT TABLE */ DESCRIPTION)
SELECT PRODUCT.SEQUENCE_NUMBER
FROM PRODUCT
SELECT XML_PRODUCT.DESCRIPTION
FROM XML_PRODUCT
I know this statement is incorrect, but it will help to illustrate the problem that I am running into. Basically, I need a way to get the identity value of the record I just inserted and put that value along with other values into the child tables. Any help or direction on this would certainly be appreciated.
I have 1 parent table and 3 child tables that are all related by an identity field in the parent table (sequence_number). I have the following statements in my stored procedure
INSERT INTO PRODUCT (NAME,
NUMBER,
MAKE,
TYPE,
MODEL)
SELECT DISTINCT XML_PRODUCT.NAME,
XML_PRODUCT.NUMBER,
XML_PRODUCT.MAKE,
XML_PRODUCT.TYPE,
XML_PRODUCT.MODEL
FROM XML_PRODUCT
This insert works great on the parent table, but when it is inserted, the identity field for each record inserted is populated with the next available number. My question is, how can I get the identity number from each record inserted to insert into the child tables like this ...
INSERT INTO PRODUCT_DESCRIPTION (SEQUENCE_NUMBER, /*IDENTITY FROM PARENT TABLE */ DESCRIPTION)
SELECT PRODUCT.SEQUENCE_NUMBER
FROM PRODUCT
SELECT XML_PRODUCT.DESCRIPTION
FROM XML_PRODUCT
I know this statement is incorrect, but it will help to illustrate the problem that I am running into. Basically, I need a way to get the identity value of the record I just inserted and put that value along with other values into the child tables. Any help or direction on this would certainly be appreciated.