1
DECLARE @barcode XML

            SET @barcode = '<BCODES><BCODE>a</BCODE><BCODE>b</BCODE><BCODE>c</BCODE><BCODE>d</BCODE></BCODES>'

            --INSERT INTO #barcode
            SELECT      v.x.value('BCODE[1]','VARCHAR(15)') AS Barcodes
            FROM        @barcode.nodes('BCODES') v(x)

Result-->

Barcodes

a

I'm unable to get b,c and d in the output.

1
  • To clarify: you expect SELECT to return a, b, c, d but only a is returned? Commented Nov 14, 2017 at 7:21

2 Answers 2

1

Just do this:

SELECT v.x.value('.','VARCHAR(15)') AS Barcodes
FROM @barcode.nodes('BCODES/BCODE') v(x)

The idea is first to get all BCODE nodes and then to extract its values.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You could try :

DECLARE @barcode XML;
SET @barcode = '<BCODES><BCODE>a</BCODE><BCODE>b</BCODE><BCODE>c</BCODE><BCODE>d</BCODE></BCODES>';

            --INSERT INTO #barcode

SELECT barcode = n.v.value('.[1]', 'NVARCHAR(128)')
FROM @barcode.nodes('BCODES/BCODE') AS n(v);

Result :

barcode 
a
b
c
d

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.