Mainframe COBOL db2 delete program

喜夏-厌秋 提交于 2019-12-12 06:58:02

问题


Detail question is my next question -- please check below link

DB2/Cursor program working in cobol


回答1:


This should be a 2 step process. First identify the records that are to be deleted and then delete those records in the 2nd step. I think, you'll Not be able to delete the records from the same table you are fetching, that's why 2 steps.

Step 1:

Select Concat(A.ClientId, A.PhoneNumber, A.Timestamp) from MyTable A
 Where Concat(A.ClientId, A.PhoneNumber, A.Timestamp)
Not IN (Select Concat(B.ClientId, B.PhoneNumber, Min(B.Timestamp))
    from MyTable B
    Group by B.ClientId, B.PhoneNumber);

Step 2:

Delete from MyTable
 Where Concat(A.ClientId, A.PhoneNumber, A.Timestamp) IN (all the values you got from Step1);

You can run step 1, create a dataset to get all the values and use that dataset in step 2. If you are running dynamic then a cut paste will do, else you'll have to modify the dataset using SORT to create a query out of it. That will be another Step in the middle of step 1 and 2.

.



来源:https://stackoverflow.com/questions/47152124/mainframe-cobol-db2-delete-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!