Merge Prescriptions into EMR Patient Prescriptions Table
This SQL statement merges data from the source table into the destination table 'emr.PATIENT_PRESC T1'. The source data is provided as a collection 'prescList', and each item in the collection is inserted or updated in the destination table based on a matching condition.
The 'using' clause is used to specify the source data, which is a 'select' statement that retrieves the values from each item in the 'prescList' collection. The column values of each item are mapped to the corresponding columns in the destination table.
The 'on' clause specifies the join condition for matching records between the source and destination tables. In this case, the match is based on the 'PRESC_NUM' column.
In the 'when matched' section, the existing records in the destination table are updated with the values from the source table. The 'update set' clause updates various columns in the destination table with the corresponding values from the source table. The 'gmt_modify' and 'DATA_VERSION' columns are also updated with the current timestamp and an incremented value, respectively.
In the 'when not matched' section, the new records from the source table are inserted into the destination table. The 'insert' clause specifies the columns to be inserted and their corresponding values from the source table.
Two additional columns, 'WARD_DEPT_ID' and 'BED_NO', have been added to the destination table. These columns are included in both the update and insert sections.
Please note that there is a comment at the end of the SQL statement stating that the column definitions are unclear. The comment mentions the addition of the 'WARD_DEPT_ID' and 'BED_NO' columns, but it is not clear what their purpose or data types are.
原文地址: http://www.cveoy.top/t/topic/dxgc 著作权归作者所有。请勿转载和采集!