日期:2014-05-16 浏览次数:20364 次
select max(case when t.v.value('local-name(.)','varchar(100)')='GUID' then t.v.value('.','varchar(36)') else null end) as [GUID],
max(case when t.v.value('local-name(.)','varchar(100)')='UserId' then t.v.value('.','varchar(20)') else null end) as [UserId],
.....
from @xml.nodes('/row/*') t(v)
DECLARE @s XML,@idoc INT
SET @s='<row>
<guid>1001a</guid>
<userId>admin</userId>
<email>103213455@qq.com</email>
<tel>13625374857</tel>
</row>'
EXEC sp_xml_preparedocument @idoc OUTPUT, @s
BEGIN TRY
BEGIN TRAN
SELECT
*
FROM OPENXML (@idoc, 'row',3)
WITH
(
[guid] varchar(50) 'guid[1]',
[userId] varchar(50) 'userId[1]',
[email] nvarchar(50) 'email[1]',
[tel] varchar(50) 'tel[1]'
)
COMMIT TRAN
END TRY
BEGIN CATCH
DECLARE @Error NVARCHAR(200)
SET @Error=ERROR_MESSAGE()
RAISERROR 50001 @Error
ROLLBACK TRAN
END CATCH
EXEC sp_xml_removedocument @idoc
/*guid userId email &n