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 SQL Server 2005中XML属性的读取值_Sql Server_Xml_Tsql - Fatal编程技术网

Sql server SQL Server 2005中XML属性的读取值

Sql server SQL Server 2005中XML属性的读取值,sql-server,xml,tsql,Sql Server,Xml,Tsql,我有一个表包含名为source的字段和varchar(max) 该字段具有以下值 <OutPatientMedication DateFormat="MM-dd-yyyy" MedicationName="lisinopril 10 mg oral tablet" Instructions="2 cap(s) orally once a day " Status="Active" Quantity="0"

我有一个表包含名为source的字段和varchar(max)

该字段具有以下值

<OutPatientMedication 
      DateFormat="MM-dd-yyyy" 
      MedicationName="lisinopril 10 mg oral tablet" 
      Instructions="2 cap(s) orally once a day " 
      Status="Active" 
      Quantity="0" 
      Refills="0" 
      PrescriptionType="E">
</OutPatientMedication>

现在我想获取指令属性的值

我如何获取价值

如能及时答复,将不胜感激

谢谢,
Dhruval Shah

试试这样的方法:

SELECT
    CAST(Source AS XML).value('(/OutPatientMedication/@Instructions)[1]', 'varchar(200)')
FROM
    dbo.YourTable
WHERE
    (condition)
这将为您提供所需的值

如果该列中确实只有XML,我强烈建议将其设置为数据库中的
XML
类型!使您的生活更加轻松,也节省了磁盘空间。

谢谢:),这里我无法更改生产中的数据类型。但我会记住你的建议。