0

I have a XML like this

<CA006 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.o`enter code here`rg/2001/XMLSchema">
  <comCode>1010</comCode>
  <transDate />
  <postDate>20130709</postDate>
  <period>7 </period>
  <rate />
  <docDate>20130709</docDate>
  <Currency>IDR</Currency>
  <headerNote />
  <DocType>KR</DocType>
  <InvoiceDate>09.07.2013</InvoiceDate>
  <PostingDate>09.07.2013</PostingDate>
  <Reference>0000000000000000</Reference>
  <Amount>0</Amount>
  <TaxAmount>0</TaxAmount>
  <fiscalYear>2013</fiscalYear>
  <fiscalPeriod>7 </fiscalPeriod>
  <BaselineDate>09.07.2013</BaselineDate>
  <PaymentBlock />
  <Assignment />
  <Notes />
  <docItemCredit006>
    <CA006DocumentCredit>
      <glAccNo>0000000001</glAccNo>
      <postingKey>40</postingKey>
      <account>2005002000</account>
      <amount>200000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>1</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000002</glAccNo>
      <postingKey>40</postingKey>
      <account>2005003000</account>
      <amount>250000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>2</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000003</glAccNo>
      <postingKey>40</postingKey>
      <account>2005004000</account>
      <amount>300000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>3</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000004</glAccNo>
      <postingKey>40</postingKey>
      <account>2005015000</account>
      <amount>400000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>4</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000005</glAccNo>
      <postingKey>40</postingKey>
      <account>2005012000</account>
      <amount>500000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>5</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000006</glAccNo>
      <postingKey>31</postingKey>
      <account>115740</account>
      <amount>200000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>1</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000007</glAccNo>
      <postingKey>31</postingKey>
      <account>115740</account>
      <amount>250000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>2</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000008</glAccNo>
      <postingKey>31</postingKey>
      <account>115740</account>
      <amount>300000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>3</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000009</glAccNo>
      <postingKey>31</postingKey>
      <account>115740</account>
      <amount>400000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>4</dokumenKe>
    </CA006DocumentCredit>
    <CA006DocumentCredit>
      <glAccNo>0000000010</glAccNo>
      <postingKey>31</postingKey>
      <account>115740</account>
      <amount>500000</amount>
      <amountLocal />
      <profitCenter>A3100015</profitCenter>
      <bussinessPlace>F203</bussinessPlace>
      <assigment />
      <text />
      <refkey1>F203</refkey1>
      <refkey2>F203</refkey2>
      <refkey3>F203</refkey3>
      <plant>F203</plant>
      <dokumenKe>5</dokumenKe>
    </CA006DocumentCredit>
  </docItemCredit006>
  <docItemKZ>
    <F04AccDoc>
      <postingKey>50</postingKey>
      <Amount>200000</Amount>
      <Assignment />
      <Text>TEST</Text>
      <ProfitCenter />
      <Plant />
      <LocalAmount />
      <glAccNo>1000101585</glAccNo>
      <businessPlace>C000</businessPlace>
      <ref1>TST</ref1>
      <ref2>TEST</ref2>
      <ref3 />
      <cashflowcode>BAX</cashflowcode>
      <cashflowTrader>TEST</cashflowTrader>
      <dokumenKe>1</dokumenKe>
    </F04AccDoc>
    <F04AccDoc>
      <postingKey>50</postingKey>
      <Amount>250000</Amount>
      <Assignment />
      <Text>TEST</Text>
      <ProfitCenter />
      <Plant />
      <LocalAmount />
      <glAccNo>1000101585</glAccNo>
      <businessPlace>C000</businessPlace>
      <ref1>TST</ref1>
      <ref2>TEST</ref2>
      <ref3 />
      <cashflowcode>BAX</cashflowcode>
      <cashflowTrader>TEST</cashflowTrader>
      <dokumenKe>2</dokumenKe>
    </F04AccDoc>
    <F04AccDoc>
      <postingKey>50</postingKey>
      <Amount>300000</Amount>
      <Assignment />
      <Text>TEST</Text>
      <ProfitCenter />
      <Plant />
      <LocalAmount />
      <glAccNo>1000101585</glAccNo>
      <businessPlace>C000</businessPlace>
      <ref1>TST</ref1>
      <ref2>TEST</ref2>
      <ref3 />
      <cashflowcode>BAX</cashflowcode>
      <cashflowTrader>TEST</cashflowTrader>
      <dokumenKe>3</dokumenKe>
    </F04AccDoc>
    <F04AccDoc>
      <postingKey>50</postingKey>
      <Amount>400000</Amount>
      <Assignment />
      <Text>TEST</Text>
      <ProfitCenter />
      <Plant />
      <LocalAmount />
      <glAccNo>1000101585</glAccNo>
      <businessPlace>C000</businessPlace>
      <ref1>TST</ref1>
      <ref2>TEST</ref2>
      <ref3 />
      <cashflowcode>BAX</cashflowcode>
      <cashflowTrader>TEST</cashflowTrader>
      <dokumenKe>4</dokumenKe>
    </F04AccDoc>
    <F04AccDoc>
      <postingKey>50</postingKey>
      <Amount>500000</Amount>
      <Assignment />
      <Text>TEST</Text>
      <ProfitCenter />
      <Plant />
      <LocalAmount />
      <glAccNo>1000101585</glAccNo>
      <businessPlace>C000</businessPlace>
      <ref1>TST</ref1>
      <ref2>TEST</ref2>
      <ref3 />
      <cashflowcode>BAX</cashflowcode>
      <cashflowTrader>TEST</cashflowTrader>
      <dokumenKe>5</dokumenKe>
    </F04AccDoc>
  </docItemKZ>
</CA006>

then I insert to table with this statement :

insert into tblXML(ReqID,ReqData) VALUES ('5101','<?xml version="1.0" encoding="utf-8"?>  <CA006 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <comCode>1010</comCode>    <transDate />    <postDate>20130709</postDate>    <period>7 </period>    <rate />    <docDate>20130709</docDate>    <Currency>IDR</Currency>    <headerNote />    <DocType>KR</DocType>    <InvoiceDate>09.07.2013</InvoiceDate>    <PostingDate>09.07.2013</PostingDate>    <Reference>0000000000000000</Reference>    <Amount>0</Amount>    <TaxAmount>0</TaxAmount>    <fiscalYear>2013</fiscalYear>    <fiscalPeriod>7 </fiscalPeriod>    <BaselineDate>09.07.2013</BaselineDate>    <PaymentBlock />    <Assignment />    <Notes />    <docItemCredit006>      <CA006DocumentCredit>        <glAccNo>0000000001</glAccNo>        <postingKey>40</postingKey>        <account>2005002000</account>        <amount>200000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>1</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000002</glAccNo>        <postingKey>40</postingKey>        <account>2005003000</account>        <amount>250000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>2</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000003</glAccNo>        <postingKey>40</postingKey>        <account>2005004000</account>        <amount>300000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>3</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000004</glAccNo>        <postingKey>40</postingKey>        <account>2005015000</account>        <amount>400000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>4</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000005</glAccNo>        <postingKey>40</postingKey>        <account>2005012000</account>        <amount>500000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>5</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000006</glAccNo>        <postingKey>31</postingKey>        <account>115740</account>        <amount>200000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>1</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000007</glAccNo>        <postingKey>31</postingKey>        <account>115740</account>        <amount>250000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>2</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000008</glAccNo>        <postingKey>31</postingKey>        <account>115740</account>        <amount>300000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>3</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000009</glAccNo>        <postingKey>31</postingKey>        <account>115740</account>        <amount>400000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>4</dokumenKe>      </CA006DocumentCredit>      <CA006DocumentCredit>        <glAccNo>0000000010</glAccNo>        <postingKey>31</postingKey>        <account>115740</account>        <amount>500000</amount>        <amountLocal />        <profitCenter>A3100015</profitCenter>        <bussinessPlace>F203</bussinessPlace>        <assigment />        <text />        <refkey1>F203</refkey1>        <refkey2>F203</refkey2>        <refkey3>F203</refkey3>        <plant>F203</plant>        <dokumenKe>5</dokumenKe>      </CA006DocumentCredit>    </docItemCredit006>    <docItemKZ>      <F04AccDoc>        <postingKey>50</postingKey>        <Amount>200000</Amount>        <Assignment />        <Text>TEST</Text>        <ProfitCenter />        <Plant />        <LocalAmount />        <glAccNo>1000101585</glAccNo>        <businessPlace>C000</businessPlace>        <ref1>TST</ref1>        <ref2>TEST</ref2>        <ref3 />        <cashflowcode>BAX</cashflowcode>        <cashflowTrader>TEST</cashflowTrader>        <dokumenKe>1</dokumenKe>      </F04AccDoc>      <F04AccDoc>        <postingKey>50</postingKey>        <Amount>250000</Amount>        <Assignment />        <Text>TEST</Text>        <ProfitCenter />        <Plant />        <LocalAmount />        <glAccNo>1000101585</glAccNo>        <businessPlace>C000</businessPlace>        <ref1>TST</ref1>        <ref2>TEST</ref2>        <ref3 />        <cashflowcode>BAX</cashflowcode>        <cashflowTrader>TEST</cashflowTrader>        <dokumenKe>2</dokumenKe>      </F04AccDoc>      <F04AccDoc>        <postingKey>50</postingKey>        <Amount>300000</Amount>        <Assignment />        <Text>TEST</Text>        <ProfitCenter />        <Plant />        <LocalAmount />        <glAccNo>1000101585</glAccNo>        <businessPlace>C000</businessPlace>        <ref1>TST</ref1>        <ref2>TEST</ref2>        <ref3 />        <cashflowcode>BAX</cashflowcode>        <cashflowTrader>TEST</cashflowTrader>        <dokumenKe>3</dokumenKe>      </F04AccDoc>      <F04AccDoc>        <postingKey>50</postingKey>        <Amount>400000</Amount>        <Assignment />        <Text>TEST</Text>        <ProfitCenter />        <Plant />        <LocalAmount />        <glAccNo>1000101585</glAccNo>        <businessPlace>C000</businessPlace>        <ref1>TST</ref1>        <ref2>TEST</ref2>        <ref3 />        <cashflowcode>BAX</cashflowcode>        <cashflowTrader>TEST</cashflowTrader>        <dokumenKe>4</dokumenKe>      </F04AccDoc>      <F04AccDoc>        <postingKey>50</postingKey>        <Amount>500000</Amount>        <Assignment />        <Text>TEST</Text>        <ProfitCenter />        <Plant />        <LocalAmount />        <glAccNo>1000101585</glAccNo>        <businessPlace>C000</businessPlace>        <ref1>TST</ref1>        <ref2>TEST</ref2>        <ref3 />        <cashflowcode>BAX</cashflowcode>        <cashflowTrader>TEST</cashflowTrader>        <dokumenKe>5</dokumenKe>      </F04AccDoc>    </docItemKZ>  </CA006>')

I wanna seach company code with the query below :

WITH XMLNAMESPACES('CA006 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"' AS PI)
select ReqID,ReqData.query('/PI:root/PI:comCode') AS CompCode
FROM tblXML WHERE ReqID = '5101'

but the query only return the ReqID field but the compCode field is empty How to get the comCode using xQuery? Thanks before

4

1 回答 1

0
select ReqID, ReqData.query('/CA006/comCode')
from tblXML

if you want to get only value of comCode:

select ReqID, ReqData.value('(/CA006/comCode)[1]', 'nvarchar(128)') as CompCode
from tblXML
于 2013-08-12T07:59:00.497 回答