0

I have a variable called result of type Xml that contains one cell of Xml text. I cannot seem to use SELECT INTO to insert this value into another temp table.

SELECT @result
INTO dbo.xml_temp

Is there a way to achieve this?

1
  • @LukStorms you mean something like SELECT @result AS XmlOutput? Commented Feb 2, 2017 at 8:47

1 Answer 1

3

If you want to insert the XML into an existing table, you have

  • VALUES
  • or INSERT INTO ... SELECT ...:

Try this:

DECLARE @tbl TABLE(ID INT IDENTITY,TargetColumn XML);

DECLARE @SomeXML XML ='<root>test</root>';

INSERT INTO @tbl VALUES(@SomeXML);

INSERT INTO  @tbl(TargetColumn) SELECT @SomeXML;

SELECT * FROM @tbl;

If you really want to create a new temp table, your statement is just missing an alias (How should the new table know the column's name?):

SELECT @SomeXML AS SomeName INTO #tmpTable;
SELECT * FROM #tmpTable;
Sign up to request clarification or add additional context in comments.

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.