Export the data XML from the table:
--ExportDeclare@xmlXmlSet@xml= (Select*From(Select TableName=‘Schema‘, XmlData= (Select*From[Schema]where ID=337For XML auto, root (‘Schemas‘) )UnionSelect‘Schemafile‘, (SelectId, SchemaID, Data= convert (varchar ( Span style= "color: #ff00ff;" >maxfrom Schemafile where schemaid = 337 for XML auto, root (schemafiles )) Schemaexportfor XML auto, root ( "schemaexports ' @xml
Insert the exported XML data into the destination table:
1 --Now import2 3 Declare @idoc int4 5 Declare @tableName varchar(255) 6 Declare @xmlDataXML7 8 Declare @mappingExport Table(TableNamevarchar(255), xmlData XML)9 Ten execsp_xml_preparedocument@idocOutput@xml One Insert into @mappingExport A Select * - fromOPENXML (@idoc,'/schemaexports/schemaexport') - with(TableNamevarchar(255), theXmlDatanvarchar(Max)) - execSp_xml_removedocument@idocOutput - - DeclareExportcursorcursor + for SelectTableName, XmlData - from @mappingExport + A OpenExportcursor at - Fetch fromExportcursor into @tableName,@xmlData - - while @ @fetch_status <> -1 - begin - execsp_xml_preparedocument@idocOutput@xmlData in - if(@tableName = 'Schema') to begin + Print 'Copying Schema' - the Select * * fromOPENXML (@idoc,'/schemas/schema') $ with(Idint,Panax NotoginsengTenantIdint, -Versionnoint, theResponseschemaidint, +SchemaNamenvarchar( $), ASoapactinovarchar( $), theLastupdatedutcdatetime, +Iscanonicalbit, -DocumentTypenvarchar( +) ) $ End $ Else if(@tableName = 'Schemafile') - begin - Print 'Copying schemafile' the Select *,datalength(data),Convert(XML, data) - fromOPENXML (@idoc,'/schemafiles/schemafile')Wuyi with(Idint, theSchemaIDint, -Datavarchar(Max), WuFileNamenvarchar(255), -FullPathnvarchar(255), AboutRelativePathnvarchar(255) ) $ End - execSp_xml_removedocument@idoc - Fetch Next fromExportcursor into @tableName,@xmlData - End A + Select datalength(data),Convert(XML, data) the fromSchemafile - whereSchemaID= 337
Migration data on SQL