我制作了一份SSIS 2014套餐(项目部署)。
在这里,您可以看到它的XML内容(相关)部分:
<DTS:Executable DTS:refId="Package\Drop and Create statements voor tabellen\Drop and Create Classes_staging" DTS:CreationName="Microsoft.ExecuteSQLTask" DTS:Description="Execute SQL Task" DTS:DTSID="{60C174A8-D9C0-4F2A-B783-77753552BFCB}" DTS:ExecutableType="Microsoft.ExecuteSQLTask" DTS:LocaleID="-1" DTS:ObjectName="Drop and Create Classes_staging" DTS:TaskContact="Execute SQL Task; Microsoft Corporation; SQL Server 2014; © 2014 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1" DTS:ThreadHint="7">
<DTS:Variables />
<DTS:ObjectData>
<SQLTask:SqlTaskData xmlns:SQLTask="www.microsoft.com/sqlserver/dts/tasks/sqltask" SQLTask:Connection="{c25e8858-9d6b-424d-b231-3ae05aed0d4b}" SQLTask:SqlStatementSource="/****** Table [dbo].[Classes_staging] ******/
IF OBJECT_ID('[dbo].[Classes_staging]') IS NOT NULL
DROP TABLE [dbo].[Classes_staging];
GO

CREATE TABLE [dbo].[Classes_staging](
	[Reference] [nvarchar](50) NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


" />
</DTS:ObjectData>
</DTS:Executable>
使用OPENROWSET将此文件导入表:
INSERT INTO Packages(XMLContent)
SELECT CONVERT(XML, BulkColumn) AS xContent
FROM OPENROWSET(BULK 'myFile.dtsx', SINGLE_BLOB) AS x;
现在我正在尝试查询它:
;WITH XMLNAMESPACES ('www.microsoft.com/SqlServer/Dts' AS
DTS,'www.microsoft.com/sqlserver/dts/tasks/sqltask' AS SQLTask)
--Alle Executables
SELECT Pkg.props.value('./@DTS:DTSID','nvarchar(max)') as [DTSID]
,Pkg.props.value('./@DTS:refId','nvarchar(max)') as [Executable]
,Pkg.props.value('./@DTS:ObjectName','nvarchar(max)') as [ObjectName]
,Pkg.props.value('./@DTS:Description','nvarchar(max)') as [Description]
,Pkg.props.value('./@DTS:ExecutableType','nvarchar(max)') as [ExecutableType]
,Pkg.props.value('./@SQLTask:SqlStatementSource','nvarchar(max)') as [SqlStatementSource]
FROM (SELECT XMLContent AS pkgXML FROM packages) t
--CROSS APPLY pkgXML.nodes('//SQLTask:SqlTaskData') Pkg(props)
CROSS APPLY pkgXML.nodes('//DTS:Executable' ) Pkg(props)
我可以找到包中使用的所有SQLStatements OR 我可以找到有关可执行文件的详细信息。我可以通过交换上面提到的两个 CROSS APPLY 来做到这一点。 但我不能两者兼顾......我在这里缺少什么?
答案 0 :(得分:2)
;WITH XMLNAMESPACES ('www.microsoft.com/SqlServer/Dts' AS
DTS,'www.microsoft.com/sqlserver/dts/tasks/sqltask' AS SQLTask)
--Alle Executables
SELECT X.Exe.value('./@DTS:DTSID','nvarchar(max)') as [DTSID]
,X.Exe.value('./@DTS:refId','nvarchar(max)') as [Executable]
,X.Exe.value('./@DTS:ObjectName','nvarchar(max)') as [ObjectName]
,X.Exe.value('./@DTS:Description','nvarchar(max)') as [Description]
,X.Exe.value('./@DTS:ExecutableType','nvarchar(max)') as [ExecutableType]
,Y.Task.value('./@SQLTask:SqlStatementSource','nvarchar(max)') as [SqlStatementSource]
FROM (SELECT XMLContent AS pkgXML FROM packages) t
CROSS APPLY pkgXML.nodes('//DTS:Executable' ) X(Exe)
OUTER APPLY X.Exe.nodes('./DTS:ObjectData/SQLTask:SqlTaskData') Y(Task)
答案 1 :(得分:1)
在第一个CROSS APPLY
的结果上执行另一个SqlTaskData
,在CROSS APPLY
上粉碎XML:
;WITH XMLNAMESPACES ('www.microsoft.com/SqlServer/Dts' AS
DTS,'www.microsoft.com/sqlserver/dts/tasks/sqltask' AS SQLTask)
--Alle Executables
SELECT Y.Task.value('./@DTS:DTSID','nvarchar(max)') as [DTSID]
,Y.Task.value('./@DTS:refId','nvarchar(max)') as [Executable]
,Y.Task.value('./@DTS:ObjectName','nvarchar(max)') as [ObjectName]
,Y.Task.value('./@DTS:Description','nvarchar(max)') as [Description]
,Y.Task.value('./@DTS:ExecutableType','nvarchar(max)') as [ExecutableType]
,X.Exe.value('./@SQLTask:SqlStatementSource','nvarchar(max)') as [SqlStatementSource]
FROM (SELECT XMLContent AS pkgXML FROM packages) t
CROSS APPLY pkgXML.nodes('//DTS:Executable' ) X(Exe)
CROSS APPLY X.Exe.nodes('./DTS:ObjectData/SQLTask:SqlTaskData') Y(Task)