如果我有一个像这样定义的SQL Server表:
CREATE TABLE MyData
(
StepDescription VARCHAR(500),
StepDatetime DATETIME,
Filedata XML
)
在一条记录中,Filedata
是:
<DocumentElement>
<Data>
<Security>BBG008LF20Q4</Security>
<IsValidSecurityID>Y</IsValidSecurityID>
<PX_LAST>101.073000</PX_LAST>
<LAST_UPDATE_DT>2017/09/01</LAST_UPDATE_DT>
<CRNCY>USD</CRNCY>
<YellowKey>Corp</YellowKey>
<YellowKeySpecified>true</YellowKeySpecified>
<GenevaID>00206RCM2</GenevaID>
<InvestmentCurrency>USD</InvestmentCurrency>
</Data>
<Data>
<Security>BBG0050NM379</Security>
<IsValidSecurityID>Y</IsValidSecurityID>
<PX_LAST>103.405000</PX_LAST>
<LAST_UPDATE_DT>2017/09/01</LAST_UPDATE_DT>
<CRNCY>USD</CRNCY>
<YellowKey>Corp</YellowKey>
<YellowKeySpecified>true</YellowKeySpecified>
<GenevaID>257867AZ4</GenevaID>
<InvestmentCurrency>USD</InvestmentCurrency>
</Data>
</DocumentElement>
在记录2中,Filedata
是:
<DocumenElement>
<Data>
<Security>86765LAC1</Security>
<IsValidSecurityID>Y</IsValidSecurityID>
<MARKET_SECTOR_DES>Corp</MARKET_SECTOR_DES>
<SECURITY_TYP>GLOBAL</SECURITY_TYP>
<CRNCY>USD</CRNCY>
<ID_BB_GLOBAL>BBG00DR79B93</ID_BB_GLOBAL>
<ID_BB_UNIQUE>COQZ4428111</ID_BB_UNIQUE>
<ID_CUSIP>86765LAC1</ID_CUSIP>
<ID_ISIN>US86765LAC19</ID_ISIN>
<TICKER>SUN</TICKER>
<EXCH_CODE>NEW YORK</EXCH_CODE>
<PARSEKYABLE_DES>QZ442811 Corp</PARSEKYABLE_DES>
<NAME>SUNOCO LP/FINANCE CORP</NAME>
<ID_BB_SEC_NUM_DES>SUN 5.5 08/01/20</ID_BB_SEC_NUM_DES>
<ID_BB_ULTIMATE_PARENT_CO_NAME>Sunoco LP</ID_BB_ULTIMATE_PARENT_CO_NAME>
<ID_MIC1>XNYS</ID_MIC1>
<CPN_CRNCY>USD</CPN_CRNCY>
<LONG_COMP_NAME>Sunoco LP / Sunoco Finance Corp</LONG_COMP_NAME>
<ADJUSTABLE>N</ADJUSTABLE>
<CPN_TYP>FIXED</CPN_TYP>
<CNTRY_ISSUE_ISO>US</CNTRY_ISSUE_ISO>
<COUNTRY>US</COUNTRY>
<IS_QDI_ELIGIBLE>No</IS_QDI_ELIGIBLE>
<_x0020_EXCH_CODE>NEW YORK</_x0020_EXCH_CODE>
<WHEN_ISSUED>N</WHEN_ISSUED>
<DAY_CNT_DES>30/360</DAY_CNT_DES>
<CPN>5.500000</CPN>
<CPN_FREQ>2</CPN_FREQ>
<INT_ACC_DT>2016/08/01</INT_ACC_DT>
<ISSUE_DT>2016/10/03</ISSUE_DT>
<FIRST_CPN_DT>2017/02/01</FIRST_CPN_DT>
<FIRST_CPN_PERIOD_TYP>Normal</FIRST_CPN_PERIOD_TYP>
<MATURITY>2020/08/01</MATURITY>
<MTY_TYP>CALLABLE</MTY_TYP>
<REDEMP_VAL>100.00000</REDEMP_VAL>
<PENULTIMATE_CPN_DT>2020/02/01</PENULTIMATE_CPN_DT>
<SINKABLE>N</SINKABLE>
<CUR_MKT_CAP>3130.29</CUR_MKT_CAP>
<PX_LAST>103.162000</PX_LAST>
<DAYS_TO_SETTLE>2</DAYS_TO_SETTLE>
<PAY_IN_KIND_BONDS>N</PAY_IN_KIND_BONDS>
<US_SECTION_13F_SECURITY>N</US_SECTION_13F_SECURITY>
<RTG_MOODY>B1</RTG_MOODY>
<RTG_SP>B+</RTG_SP>
<RTG_FITCH>BB- /*+</RTG_FITCH>
<CNTRY_OF_RISK>US</CNTRY_OF_RISK>
<_x0031_44A_FLAG>N</_x0031_44A_FLAG>
<IS_REG_S>N</IS_REG_S>
<CNTRY_OF_DOMICILE>US</CNTRY_OF_DOMICILE>
<IS_EMERGING_MARKET>N</IS_EMERGING_MARKET>
<YellowKey>Corp</YellowKey>
<YellowKeySpecified>true</YellowKeySpecified>
</Data>
</DocumentElement>
现在我需要创建如下的行:
StepDescription, StepDatetime, FieldName, FieldValue
所以对于第一张唱片,我会:
Step1, 10/31/2017, Security, IsValidSecurityID
Step1, 10/31/2017, Security, PX_LAST
Step1, 10/31/2017, Security, LAST_UPDATE_DT
基本上,我试图在不事先知道节点的情况下粉碎XML。
我如何在SQL Server中实现这一目标?
感谢。