1
SELECT
ステートメントを使用してxmlファイルを作成していますが、ドキュメントに余分なノードを追加する際に問題があります。xmlパスを使用してxml出力にノードを追加する
作成された現在の構造はこれです:
<DBObjectsToUpdate>
<TablesToAdd>...</TablesToAdd>
<TableObjectsToDelete> ...</TableObjectsToDelete>
<Views>
<View> </View>
</Views>
<StoredProcedures>
<StoredProc> </StoredProc>
</StoredProcedures>
</DBObjectsToUpdate>
私が何をしたいのか「ビュー」と「StoredProcedures」の周りに、周囲のノードを追加しています。だから、次のようになります。
<DBObjectsToUpdate>
<TablesToAdd>...</TablesToAdd>
<TableObjectsToDelete> ...</TableObjectsToDelete>
<TableObjectsToAdd>
<Views>
<View> </View>
</Views>
<StoredProcedures>
<StoredProc> </StoredProc>
</StoredProcedures>
</TableObjectsToAdd>
</DBObjectsToUpdate>
これは、SELECT文の関連する部分である:私は外のノードにビューとストアドプロシージャのノードをカプセル化するにはどうすればよい
SELECT
[Table].TableName AS "@TName", SchemaName AS "@Schema",
TextImageFileGroup AS "@TextImageOnFileGroup",
..bunch of stuff that is not important for this question
FROM
(a select statement to get the tables) AS [Table]
(--Returns all of the Triggers - Currently there are no triggers
SELECT
[Trig].TriggerName AS "@TriggerName",
[Trig].TrigDefinition AS "@TrigDefinition"
FROM
(SELECT DISTINCT S7.TableName, S7.TriggerName, TrigDefinition
FROM #SourceDBObjects S7
JOIN #TableObjectsToAdd T7 ON S7.TableName = T7.TableName
AND S7.TriggerName = T7.TriggerName
AND T7.TriggerName IS NOT NULL) AS [Trig]
WHERE
[Table].TableName = [Trig].TableName
FOR XML PATH('Trigger'), TYPE) AS [Triggers]
FROM
(SELECT DISTINCT T.TableName, S.SchemaName, S.TextImageFileGroup
FROM #TableObjectsToAdd T
JOIN #SourceDBObjects S ON T.TableName = S.TableName) AS [Table]
ORDER BY
"@TName"
FOR XML PATH ('Table'), TYPE) as [TableObjectsToAdd],
(--Returns all of the check constrains for table
SELECT [CkCon].CheckName AS "@CkName", [CkCon].CkDefinition AS "@CkDefinition", [CkCon].IsCkDisabled AS "@IsCkDisabled"
FROM (SELECT DISTINCT T5.TableName, T5.CheckName, CkDefinition, IsCkDisabled
FROM #TargetDBObjects T5 JOIN #TableObjectsToDelete D5 ON T5.TableName = D5.TableName AND T5.DefaultName = T5.CheckName AND D5.CheckName IS NOT NULL) AS [CkCon]
WHERE [Table].TableName = [CkCon].TableName
FOR XML PATH('Check'),
TYPE
) AS [CheckConstraints]
FROM (
SELECT DISTINCT D.TableName, T.SchemaName, T.TextImageFileGroup
FROM #TableObjectsToDelete D JOIN #TargetDBObjects T ON T.TableName = D.TableName
) AS [Table]
ORDER BY "@TName"
FOR XML PATH ('Table'), TYPE)
as [TableObjectsToDelete],
( ------VIEWS NODE------
SELECT ObjectName AS "@VName", REPLACE(ObjectText, '''', '''''') AS "@VDefinition"
FROM #SourceViewsSPFunctionsToAdd
WHERE ObjectType = 'View'
FOR XML PATH ('View'), TYPE
) AS [Views],
( ------STORED PROCEDURES NODE------
SELECT ObjectName AS "@SPName", REPLACE(ObjectText, '''', '''''') AS "@SPDefinition"
FROM #SourceViewsSPFunctionsToAdd
WHERE ObjectType = 'StoredProcedure'
FOR XML PATH ('StoredProcedure'), TYPE
) AS [StoredProcedures],
FOR XML PATH(''),
ROOT('DBObjectsToUpdate')
いない要素や属性?
greateのに!私はあなたが[自己学習者バッジ](http://stackoverflow.com/help/badges/14/self-learner)を得ることを願っています。私はそれにスタートを与える:+1 :-) – Shnugo