我想查询一个表,其中包含直xml数据的列。在查询中,我正在查询包含直接数据的列(int,vchar等),但我也在查询xml列。在xml列中,我想要在xml中获取一个值,如果它不存在,则返回null。我有以下查询几乎可以工作,但返回重复。需要帮忙!SQL查询/ Xml
我有我的根xml CodeFiveReport然后在它的属性,并在该属性中有一个序列号。我试图抓住序列号,如果它存在并显示它。
select Distinct rs.Id
, rs.CaseNumber
, rs.StartDate
, rs.[Status]
, rs.PatrolDistrict
, rs.PrimaryUnit
, rs.Location
, rs.ReportType
, rs.IncidentType
, rs.UserId
, rs.UnitId
, rs.UnitCode
, rs.IsLocked
, rs.LockedBy
, rs.AgencyId
, rl.ReportName
, rl.ParentId
, TempTable.Party.value('(SerialNumber/text())[1]', 'varchar(50)') as SerialNumber
from dbo.vw_ReportSummary rs OUTER APPLY Report.nodes('/CodeFiveReport/Properties/Property') AS TempTable(Party)
left outer join dbo.ReportLookup rl on rs.Id = rl.Id
where rs.[Status] = 'Approved'
order by rs.Id
如果DISTINCT返回重复项,那些重复项并不重复 - 请检查您的数据! – 2010-07-11 20:22:54
每个结果返回的序列号是不同的......我需要知道的是,如果特定记录的xml包含任何序列号,而不是全部序列号。这是我无法想象如何去做的 – mint 2010-07-11 22:04:44