码迷,mamicode.com
首页 > 其他好文 > 详细

XML 类型数据转化为表

时间:2017-12-26 18:02:14      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:asc   sele   custom   int   tom   second   creat   post   char   


BEGIN TRAN
DECLARE @XMLDocument XML
SET @XMLDocument=‘<Root>
<Row><A>文涛</A><B>0</B><C>3123</C><D>2017-06-09 09:42:59.000</D></Row>
<Row><A>云芬</A><B>0</B><C>23432</C><D>2017-06-09 09:52:53.233</D></Row>
<Row><A>祥君</A><B>0</B><C>432432</C><D>2017-06-09 09:52:53.593</D></Row>

</Root>‘
SELECT T.c.value(‘(A[1])‘, ‘varchar(20)‘) AS Name,T.c.value(‘(B[1])‘,‘int‘) AS Cert_Type,T.c.value(‘(C[1])‘,‘varchar(30)‘) AS Cert_No, T.c.value(‘(D[1])‘,‘datetime‘) AS Time_stamp INTO #temp
FROM @XMLDocument.nodes(‘/Root/Row‘) AS T ( c )

--ROLLBACK TRAN
COMMIT TRAN

SELECT a.Cert_Type,* FROM #temp A FULL JOIN CustomerCredit.Compliance.Request B ON a.Cert_No=b.IdentityNo AND b.Source=‘VBS‘

WHERE B.IdentityNo IS NULL

SELECT id FROM (
SELECT ROW_NUMBER() OVER( PARTITION BY c.IdentityNo ORDER BY C.mintime ASC) num ,id FROM ( SELECT ABS(DATEDIFF(SECOND, a.Time_stamp,b.CreateTime)) AS mintime ,B.ID,B.IdentityNo
FROM #temp A JOIN CustomerCredit.Compliance.Request B ON a.Cert_No=b.IdentityNo AND b.Source=‘VBS‘ ) C ) D WHERE D.num=1

 

XML 类型数据转化为表

标签:asc   sele   custom   int   tom   second   creat   post   char   

原文地址:https://www.cnblogs.com/wdnrsjd/p/8118433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!