0
XML列には次の構造があります。それはshow stored procedures
となっており、下にリストused tables and columns
となっています。XQueryクロス適用で余分なレコードが返される
追加のレコードが表示されています。構造およびクエリは、下記を参照してください:私は(あなたが無関係な行を参照)を取得
CREATE TABLE #T (
ID int primary key,
MetaData xml
)
insert into #T values(1,
'<root>
<object name="myProc">
<tables>
<table database="LynxReporting" schema="Secure" name="factPortCore">
<columns>
<column name="SnapshotKey"/>
<column name="SnapshotDt"/>
</columns>
</table>
<table database="LynxSnapshot" schema="dbo" name="Loan">
<columns>
<column name="LoanProgId"/>
<column name="FinType"/>
</columns>
</table>
<table database="LynxReporting" schema="dbo" name="dimGLSrcSysId">
<columns>
<column name="GLSrcSysId"/>
</columns>
</table>
</tables>
</object>
<object name="usp_Recon">
<tables>
<table database="LynxReporting" schema="Secure" name="dimAppSysId">
<columns>
<column name="AppSysId"/>
<column name="AppSysIdLongDesc"/>
</columns>
</table>
</tables>
</object>
</root>')
SELECT
t.x.value('@name', 'varchar(max)') as TableName
, c.x.value('@name', 'varchar(max)') as ColumnName
FROM #T
CROSS APPLY MetaData.nodes('root/object/tables/table') as t(x)
CROSS APPLY MetaData.nodes('root/object/tables/table/columns/column') as c(x)
order by 1,2
何を:私が欲しいもの
╔═══════════════╦══════════════════╗
║ TableName ║ ColumnName ║
╠═══════════════╬══════════════════╣
║ Loan ║ AppSysId ║
╠═══════════════╬══════════════════╣
║ Loan ║ AppSysIdLongDesc ║
╠═══════════════╬══════════════════╣
║ Loan ║ FinType ║
╠═══════════════╬══════════════════╣
║ Loan ║ GLSrcSysId ║
╠═══════════════╬══════════════════╣
║ Loan ║ LoanProgId ║
╠═══════════════╬══════════════════╣
║ Loan ║ SnapshotDt ║
╠═══════════════╬══════════════════╣
║ Loan ║ SnapshotKey ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ AppSysId ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ AppSysIdLongDesc ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ FinType ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ GLSrcSysId ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ LoanProgId ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ SnapshotDt ║
╠═══════════════╬══════════════════╣
║ dimAppSysId ║ SnapshotKey ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ AppSysId ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ AppSysIdLongDesc ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ FinType ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ GLSrcSysId ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ LoanProgId ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ SnapshotDt ║
╠═══════════════╬══════════════════╣
║ dimGLSrcSysId ║ SnapshotKey ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ AppSysId ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ AppSysIdLongDesc ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ FinType ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ GLSrcSysId ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ LoanProgId ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ SnapshotDt ║
╠═══════════════╬══════════════════╣
║ factPortCore ║ SnapshotKey ║
╚═══════════════╩══════════════════╝
:
╔════════════╦═══════════════╦══════════════════╗
║ ObjectName ║ TableName ║ ColumnName ║
╠════════════╬═══════════════╬══════════════════╣
║ myProc ║ Loan ║ FinType ║
╠════════════╬═══════════════╬══════════════════╣
║ myProc ║ Loan ║ LoanProgId ║
╠════════════╬═══════════════╬══════════════════╣
║ usp_Recon ║ dimAppSysId ║ AppSysId ║
╠════════════╬═══════════════╬══════════════════╣
║ usp_Recon ║ dimAppSysId ║ AppSysIdLongDesc ║
╠════════════╬═══════════════╬══════════════════╣
║ myProc ║ dimGLSrcSysId ║ GLSrcSysId ║
╠════════════╬═══════════════╬══════════════════╣
║ myProc ║ factPortCore ║ SnapshotDt ║
╠════════════╬═══════════════╬══════════════════╣
║ myProc ║ factPortCore ║ SnapshotKey ║
╚════════════╩═══════════════╩══════════════════╝
見ての通り、私も欲しいですObjectName
の列を持つ。 クエリをどのように変更する必要があるかわかりません。どんな助けもありがとうございます。
グレートから値を適用します。 – FLICKER