我已经完成了很多 XML PATH 语句,但是这个语句让我无法理解,或者甚至可能无法使用多个不同的孩子。
最终结果应该是这样的
<Process>
<TaskList>
<SqlTask Name="Get Report Parameters">
<StoredProcName>GetReportParameters</StoredProcName>
<ConnectionName>Local</ConnectionName>
<DataTableName>DistributionList</DataTableName>
<Parameters>
<Parameter>
<Name>ReportName</Name>
<Value>TheReprot</Value>
<Type>String</Type>
</Parameter>
</Parameters>
</SqlTask>
<LoopTask Name="Loop Report Creation" ContainerKey="DistributionList">
<TaskList>
<ReportTask Name="Report In Loop">
</ReportTask>
</TaskList>
</LoopTask>
<SqlTask Name="Get Email Addresses">
<StoredProcName>GetMailingAddress</StoredProcName>
<ConnectionName>Local</ConnectionName>
<DataTableName>EmailList</DataTableName>
</SqlTask>
<LoopTask Name="Loop Mail Creation" ContainerKey="EmailList">
<TaskList>
<MailTask Name="Send Email In Loop">
</MailTask>
</TaskList>
</LoopTask>
</TaskList>
</Process>
以下是我到目前为止的一些测试表和数据。问题实际上是如何在同一根目录下显示不同的子节点。我可以从列值派生标签名称吗?
CREATE TABLE #TASK (
TaskId INT IDENTITY(1,1)
, ProcessId INT
, TaskType VARCHAR(255)
, TaskName VARCHAR(255)
, ContainerKey VARCHAR(255)
, ParentTaskId INT
)
CREATE TABLE #TASK_PARAMETERS
(
TaskId INT
, Name VARCHAR(255)
, Value VARCHAR(MAX)
, [Type] VARCHAR(128)
)
CREATE TABLE #TASK_DETAILS
(
TaskId INT
, DetailName VARCHAR(255)
, DetailValue VARCHAR(MAX)
)
DECLARE @TaskId AS INT
DECLARE @ParentTaskId AS INT
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'SqlTask'
, 'Get Report Parameters'
, NULL
, NULL
)
SET @TaskId = @@IDENTITY
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'StoredProceName'
, 'GetReportParamters'
)
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'ConnectionName'
, 'Local'
)
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'DataTableName'
, 'DistributionList'
)
INSERT INTO #TASK_PARAMETERS
(
TaskId
, Name
, Value
, [Type]
)
VALUES
(
@TaskId
, 'ReportName'
, 'TheReprot'
, 'String'
)
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'LoopTask'
, 'Loop Report Creation'
, 'DistributionList'
, NULL
)
SET @ParentTaskId = @@IDENTITY
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'ReportTask'
, 'Report In Loop'
, NULL
, @ParentTaskId
)
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'SqlTask'
, 'Get Email Addresses'
, NULL
, NULL
)
SET @TaskId = @@IDENTITY
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'StoredProceName'
, 'GetMailingAddress'
)
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'ConnectionName'
, 'Local'
)
INSERT INTO #TASK_DETAILS
(
TaskId
, DetailName
, DetailValue
)
VALUES
(
@TaskId
, 'DataTableName'
, 'EmailList'
)
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'LoopTask'
, 'Loop Mail Creation'
, 'EmailList'
, NULL
)
SET @ParentTaskId = @@IDENTITY
INSERT INTO #TASK
(
ProcessId
, TaskType
, TaskName
, ContainerKey
, ParentTaskId
)
VALUES
(
0
, 'MailTask'
, 'Send Email In Loop'
, NULL
, @ParentTaskId
)
SELECT *
FROM #TASK
SELECT *
FROM #TASK_PARAMETERS
SELECT *
FROM #TASK_DETAILS