需要检查下面的程序(Get_ClientDetails),知道它是否正确

时间:2017-09-25 15:39:47

标签: sql-server

需要关注此程序,因为它发出错误。 该过程是将数据从xml字符串插入表中。 表名为SL_UnitizedScheme.SpoolUnitizedScheme,XML语法如下:

String<NewDataSet>
<Table>
<Clientname>Joy</Clientname>
<Account>3452672</Account>
<Amount>50000</Amount>
<EmployerCont>20000</EmployerCont>
</Table>
</NewDataSet>


CREATE PROCEDURE [dbo].[Get_ClientDetails]
(@XML  XML
)

AS

INSERT INTO k2.[dbo].[SL_UnitizedScheme.SpoolUnitizedScheme]
            ([ClientName]
           ,[Account]
           ,[Amount]
           ,[EmployeeCont]
           ,[status])


SELECT
value('(ClientName/text())[1]','varchar(100)') as ClientName,
value('(Account/text())[1]','varchar(100)') as Account,
value('(Amount/text())[1]','varchar(100)') as Amount,
value('(Employee/text())[1]','varchar(100)') as EmployeeCont,
'Copied'

FROM @XML.nodes('/NewDataSet/Table')
as Table(Table)

SELECT @@ROWCOUNT AS 'Rows'



GO

1 个答案:

答案 0 :(得分:0)

您的语法错误,使用&#39; table&#39;,保留关键字,或者您的SELECT中的名称与XML中的名称不匹配,没有帮助。尝试:

SELECT
MyTable.value('(Clientname/text())[1]','varchar(100)') as ClientName,
MyTable.value('(Account/text())[1]','varchar(100)') as Account,
MyTable.value('(Amount/text())[1]','varchar(100)') as Amount,
MyTable.value('(EmployerCont/text())[1]','varchar(100)') as EmployeeCont,
'Copied'
FROM @val.nodes('/NewDataSet/Table') as MyData(MyTable)