Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server XML数据导入_Sql_Xml_Date - Fatal编程技术网

SQL Server XML数据导入

SQL Server XML数据导入,sql,xml,date,Sql,Xml,Date,在将xml日期字段导入sql server时遇到问题,其他字段也可以。我尝试了很多方法,但它总是返回空值。需要帮忙吗 2014-02-18T12:15:21.357是问题所在 XML是 <?xml version="1.0" encoding="utf-8"?> <MISRoot xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/I

在将xml日期字段导入sql server时遇到问题,其他字段也可以。我尝试了很多方法,但它总是返回空值。需要帮忙吗

2014-02-18T12:15:21.357是问题所在

XML是

<?xml version="1.0" encoding="utf-8"?>
<MISRoot xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/IGUK.Evolution.FieldToolLite.Lib.MIS">
    <Claims>
        <Claim>
            <Amalgamation>
                <ChannelSolutions /> 
                <Name i:nil="true" /> 
            </Amalgamation>
            <Appointments>
                <Appointment>
                    <Access /> 
                    <AccessGranted>true</AccessGranted> 
                    <AppointmentId>320</AppointmentId> 
                    <EnterTime>2014-02-18T12:15:21.357</EnterTime> 
                    <LeaveTime i:nil="true" /> 
                    <Name i:nil="true" /> 
                </Appointment>
            </Appointments>
            <CustomProducts /> 
            <Id>1220</Id> 
            <Payments /> 
            <Tasks /> 
        </Claim>
    </Claims>
</MISRoot>

您的
XQuery
有问题,我已将您的文件复制到
XML
变量中,并能够使用以下查询进行检索

DECLARE @MyXMLVariable XML = 
'<?xml version="1.0" encoding="utf-8"?>
<MISRoot xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/IGUK.Evolution.FieldToolLite.Lib.MIS">
    <Claims>
        <Claim>
        <Amalgamation>
            <ChannelSolutions /> 
            <Name i:nil="true" /> 
        </Amalgamation>
        <Appointments>
            <Appointment>
                <Access /> 
                <AccessGranted>true</AccessGranted> 
                <AppointmentId>320</AppointmentId> 
                <EnterTime>2014-02-18T12:15:21.357</EnterTime> 
                <LeaveTime i:nil="true" /> 
                <Name i:nil="true" /> 
            </Appointment>
        </Appointments>
        <CustomProducts /> 
        <Id>1220</Id> 
        <Payments /> 
        <Tasks /> 
        </Claim>
    </Claims>
</MISRoot>';

WITH XMLNAMESPACES(DEFAULT 'http://schemas.datacontract.org/2004/07/IGUK.Evolution.FieldToolLite.Lib.MIS')
SELECT @MyXMLVariable.value('(MISRoot/Claims/Claim/Appointments/Appointment/EnterTime)[1]','DATETIME')

约会
约会的孩子
不是另一回事,
索赔
索赔的孩子
最好的方法是查看打开的标签和关闭的标签

谢谢,真的没有发现!!
DECLARE @MyXMLVariable XML = 
'<?xml version="1.0" encoding="utf-8"?>
<MISRoot xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/IGUK.Evolution.FieldToolLite.Lib.MIS">
    <Claims>
        <Claim>
        <Amalgamation>
            <ChannelSolutions /> 
            <Name i:nil="true" /> 
        </Amalgamation>
        <Appointments>
            <Appointment>
                <Access /> 
                <AccessGranted>true</AccessGranted> 
                <AppointmentId>320</AppointmentId> 
                <EnterTime>2014-02-18T12:15:21.357</EnterTime> 
                <LeaveTime i:nil="true" /> 
                <Name i:nil="true" /> 
            </Appointment>
        </Appointments>
        <CustomProducts /> 
        <Id>1220</Id> 
        <Payments /> 
        <Tasks /> 
        </Claim>
    </Claims>
</MISRoot>';

WITH XMLNAMESPACES(DEFAULT 'http://schemas.datacontract.org/2004/07/IGUK.Evolution.FieldToolLite.Lib.MIS')
SELECT @MyXMLVariable.value('(MISRoot/Claims/Claim/Appointments/Appointment/EnterTime)[1]','DATETIME')
'(MISRoot/Claims/Claim/Appointments/Appointment/EnterTime)[1]' --Correct
'(Claims/Appointment/Appointments/EnterTime)[1]' --Yours