I have to insert some records into table from the file using COBOL-DB2 program.
can we display number of records in a column in the table using the same SQL insert query?
E.g,
I have 3 fields SER_NO, EMP_NO and EMP_NAME in table and load file has only EMP-NO and EMP-NAME fileds. When I will insert a row into table it has to increase the number and insert into SER_NO column dynamically. Is there any function to perform this?
I/P file:
Code:
100 ABCD
500 BCDE
786 CDEF....
Table has following declaration.
Code:
SER_NO EMP_NO EMP_NAME
When I execute with the above file with 3 records, data has to be inserted into the table as shown below.
INSERT INTO TEST_EMPL
WITH T1 (SER_NO,EMP_NO,EMP_NAME) AS
(SELECT * FROM TEST_EMPL
WHERE SER_NO = 0)
SELECT RN + (SELECT MAX(SER_NO) FROM TEST_EMPL),EMP_NO,EMP_NAME FROM T1 A,
TABLE(SELECT COUNT(*) + 1 AS RN FROM T1 B
WHERE A.EMP_NO > B.EMP_NO) ;
DELETE FROM TEST_EMPL
WHERE SER_NO = 0;
SELECT * FROM TEST_EMPL;
INSERT INTO TEST_EMPL
WITH T1 (SER_NO,EMP_NO,EMP_NAME) AS
(SELECT * FROM TEST_EMPL
WHERE SER_NO = 0)
SELECT RN + (SELECT MAX(SER_NO) FROM TEST_EMPL),EMP_NO,EMP_NAME FROM T1 A,
TABLE(SELECT COUNT(*) + 1 AS RN FROM T1 B
WHERE A.EMP_NO > B.EMP_NO) ;
DELETE FROM TEST_EMPL
WHERE SER_NO = 0;
SELECT * FROM TEST_EMPL;