Вопрос

What is the correct way to pull the list of IDs from this document as ints?

    declare @d xml
    set @d = '<doc><id>1</id><id>2</id></doc>'

    select Data.Col.value('/text()', 'Int')
      from @d.nodes('/doc/id')
        as Data(Col)

Using the method above I get a error XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'

Это было полезно?

Решение

.value() always requires a positional reference to identify the node you want.

declare @d xml
set @d = '<doc><id>1</id><id>2</id></doc>'

select Data.Col.value('.[1]', 'Int')
  from @d.nodes('/doc/id')
    as Data(Col)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top