SELECT formId, ownerId, ownerType, formId, formName, fieldDomain, fieldCategory, publishDate, unpublishDate,synopsis, applicability, confirmationMessageTitle, confirmationMessageText, responderListId, ccSubmission, coalesce( archive, 'N' ) archive, contactFieldMapping FROM tbl_WRK_Forms with (nolock) WHERE ownerId = and ownerType = and formId = and coalesce(archive,'') <> 'Y' insert into tbl_WRK_Forms ( ownerId, ownerType , formName, fieldDomain, fieldCategory, publishDate, unpublishDate, synopsis, applicability, confirmationMessageTitle, confirmationMessageText, responderListId, ccSubmission, archive, contactFieldMapping) values ( , , , , '?', {fn now()}, , , , , , , , , ) UPDATE tbl_WRK_Forms SET fieldCategory = WHERE formId = and ownerId = and ownerType = select fieldId, ltrim( rtrim( name )) name, ltrim( rtrim( category )) category, type, label, required, message, format, sortRank, maxLength, config, active, searchable, placeholder from tbl_#_fieldDomain#_Fields f where ownerId = and ownerType = and category = select fieldId from tbl_#_fieldDomain#_Fields where ownerId = and ownerType = and name = INSERT INTO tbl_#_fieldDomain#_Fields ( ownerType, ownerId, category, name,type,label,required,message,format,sortRank,maxLength,config,active,searchable,placeholder ) VALUES ( ,, , , , , , , , , , , , , ) update tbl_#_fieldDomain#_Fields set name = where fieldId = and ownerId = and ownerType = insert into tbl_#_fieldDomain#_fieldLookups ( ownerId, ownerType, fieldName, selectionValue, selectionLabel, sortRank ) select ownerId, ownerType, '#_newFieldName#' fieldName, selectionValue, selectionLabel, sortRank from tbl_#_fieldDomain#_fieldLookups where ownerId = and ownerType = and fieldName = select * from qmd_fieldsToCopy where category = and name = UPDATE tbl_WRK_Forms SET contactFieldMapping = WHERE formId = and ownerId = and ownerType = SELECT fieldSetId, fieldSetName, fieldSetRank FROM tbl_WRK_FormFieldSets WITH (nolock) WHERE ownerId = and ownerType = and formId = INSERT INTO tbl_WRK_FormFieldSets (ownerId, ownerType, formId, fieldSetName, fieldSetRank ) VALUES (, , , , ) SELECT distinct fieldId FROM tbl_WRK_FormFieldSetFields WITH (nolock) WHERE fieldSetId = and ownerType = and ownerId = select * from qmd_fieldsToCopy where fieldId = INSERT INTO tbl_WRK_FormFieldSetFields (ownerId, ownerType, fieldSetId,fieldId ) VALUES ( , , , ) INSERT INTO tbl_WRK_FormRecipients ( ownerType, ownerId, formId, recipientType, recipientUserId ) SELECT ownerType, ownerId, formId, recipientType, recipientUserId FROM tbl_WRK_FormRecipients WITH (nolock) WHERE ownerType = AND ownerId = AND formId =