我想将从一个表中删除的记录插入到另一个表中,以便可以将已删除的记录归档,就像Windows回收站一样。为此,我使用INSERT INTO SELECT查询:
<cfquery name="archiveDeletion" datasource="#application.dsn#">
INSERT INTO deletedCylinderContentRecords (air_emissions, barcode, building, capacity, Carcinogen, carcinogen_comment, carcinogen_type, cas, casORmixture, chemicalname, concentration, containermaterial, containertype, cyanide, CylinderID, dotdivision, dothazardclass, dothazardclassSub, expirationdate, flashpoint, formula, grade, HMAR_ID, hydroflouric_acid, HydrostaticTestDate, HydrostaticTestDueDate, initial_quantity, inventoried, isdeleted, lastupdated, LeakTestDate, location, manufacturer, ModifiedBy, msds, MSDS_Scan, MSN, Mutagen, nfpablue, nfpared, nfpawater, nfpayellow, ownerid, PeroxideConcentration, PeroxideFormers, PeroxideTestDate, PeroxideTestDueDate, phaseID, PList, price, Purchase_Scan, Purchase_Scan_Link, purchasedate, remarks, ResearchSampleNo, room, sewer, shelf, ShockSensitive, specificgravity, spillage, spillclass, SPInspect, SPInspectDate, SPInterval, stocknumber, StorageRemarks, Teratogen, Undelete, units, usage_comments, usage_transferred, usage_transferred_to, usedinprocess, Validate, ValidateBy, ValidateDate, vendor, VendorNumber, waste, deleterName, timeDeleted, reasonDeleted)
SELECT * FROM containers WHERE barcode = '#session.barcode#',
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#getDeleterName.last_name#, #getDeleterName.first_name# #getDeleterName.middle_initial#.">,
SYSDATETIME(),
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.deleteReason5#">
</cfquery>
从上面的查询中,您可以看到将三列从原始表插入到归档表中。这些都是最近三:deleterName
,timeDeleted
,和reasonDeleted
。因此,在该SELECT *
部分之后,我添加了我想要的三列,以及一些<cfqueryparam>
标签。我的语法一定是错误的,因为出现此错误:
','附近的语法不正确。
正确的语法是什么?我是否需要另一个SELECT
关键字?我找不到任何东西。
感谢@SeanLange在评论中所说的,我找到了解决方案。我将三个额外的列(不是containers
表的一部分)添加到SELECT
查询中,并确保它可以正常工作。我还明确指定了列的名称,而不是使用*
选择器,因此最终的解决方案如下所示:
<cfquery name="archiveDeletion" datasource="#application.dsn#">
INSERT INTO deletedCylinderContentRecords (air_emissions, barcode, building, capacity,
Carcinogen, carcinogen_comment, carcinogen_type, cas, casORmixture, chemicalname, concentration,
containermaterial, containertype, cyanide, CylinderID, dotdivision, dothazardclass,
dothazardclassSub, expirationdate, flashpoint, formula, grade, HMAR_ID, hydroflouric_acid,
HydrostaticTestDate, HydrostaticTestDueDate, initial_quantity, inventoried, isdeleted, lastupdated,
LeakTestDate, location, manufacturer, ModifiedBy, msds, MSDS_Scan, MSN, Mutagen, nfpablue, nfpared,
nfpawater, nfpayellow, ownerid, PeroxideConcentration, PeroxideFormers, PeroxideTestDate,
PeroxideTestDueDate, phaseID, PList, price, Purchase_Scan, Purchase_Scan_Link, purchasedate,
remarks, ResearchSampleNo, room, sewer, shelf, ShockSensitive, specificgravity, spillage,
spillclass, SPInspect, SPInspectDate, SPInterval, stocknumber, StorageRemarks, Teratogen,
Undelete, units, usage_comments, usage_transferred, usage_transferred_to, usedinprocess, Validate,
ValidateBy, ValidateDate, vendor, VendorNumber, waste, deleterName, timeDeleted, reasonDeleted)
SELECT air_emissions, barcode, building, capacity, Carcinogen, carcinogen_comment, carcinogen_type,
cas, casORmixture, chemicalname, concentration, containermaterial, containertype, cyanide,
CylinderID, dotdivision, dothazardclass, dothazardclassSub, expirationdate, flashpoint, formula,
grade, HMAR_ID, hydroflouric_acid, HydrostaticTestDate, HydrostaticTestDueDate, initial_quantity,
inventoried, isdeleted, lastupdated, LeakTestDate, location, manufacturer, ModifiedBy, msds,
MSDS_Scan, MSN, Mutagen, nfpablue, nfpared, nfpawater, nfpayellow, ownerid, PeroxideConcentration,
PeroxideFormers, PeroxideTestDate, PeroxideTestDueDate, phaseID, PList, price, Purchase_Scan,
Purchase_Scan_Link, purchasedate, remarks, ResearchSampleNo, room, sewer, shelf, ShockSensitive,
specificgravity, spillage, spillclass, SPInspect, SPInspectDate, SPInterval, stocknumber,
StorageRemarks, Teratogen, Undelete, units, usage_comments, usage_transferred, usage_transferred_to,
usedinprocess, Validate, ValidateBy, ValidateDate, vendor, VendorNumber, waste,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#getDeleterName.last_name#, #getDeleterName.first_name# #getDeleterName.middle_initial#.">,
SYSDATETIME(),
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Form.deleteReason5#">
FROM containers WHERE barcode = '#session.barcode#'
</cfquery>