?
Solved

Store XML RAW result into a temp table / string variable

Posted on 2009-02-17
9
Medium Priority
?
912 Views
Last Modified: 2012-06-27
Hello Friends,
I executed the following command for getting XML result:

SELECT job_id, voyage_id FROM job FOR XML RAW

The result will be in a single column. I need this result to be stored either in a field of temporary table or in a string variable. Is it possible in SQL2000? I came to know it is possible in SQL2005, but giving error in SQL2000.
0
Comment
Question by:renjitkumar
  • 3
  • 3
  • 2
8 Comments
 
LVL 25

Accepted Solution

by:
reb73 earned 750 total points
ID: 23665814
Quoting SQL 2000 BOL -

"Generally, FOR XML cannot be used for any selections that do not produce direct output to the Microsoft® SQL Server" 2000 client"

This means FOR XML cannot be mixed with other DML syntax (in SQL 2000) unless it results in output back to the querying client..

If you need to store it in a variable, you just have to capture it in client software and send it back..

0
 
LVL 25

Expert Comment

by:reb73
ID: 23665844
SQL 2005 supports it due to the availability of the new XML datatype, which is not available in SQL 2000
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 23687879
As reb73 has stated clearly and in answer to your question it cannot be done in SQL Server 2000 without returning the output to the client.

The only reason I did not participate is because you had already been given the answer.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:renjitkumar
ID: 23690866
Is that a solution or a fact?
It haven't solved my problem. I am not sure about how can I accept this fact as a solution. I need a possible way to make this XML resultset assigned into a string variable without using any external software.
The only possibility which I am having in my mind is save the result set into a text file and read that file using my stored procedure. I think it is possible but will be time consuming operation. What you think?
0
 
LVL 25

Expert Comment

by:reb73
ID: 23691774
Your question was - "Is it possible in SQL2000?"

I gave you the answer/confirmation quoting references and the reason (XML datatype was introduced only in SQL 2005).

Yes, you could capture the output in a text/xml file using OSQL/ISQL and then read it into a character variable, but there can be other alternatives (a DTS package springs to mind) this can be addressed better if you create a new question provinding clear details of what you seek to accomplish.

0
 

Author Comment

by:renjitkumar
ID: 23694012
I am using a stored procedure to read some data from excel sheet and it will process the data accordingly and will result a huge recordset. This need to be inserted into a particular text field of a table which will later used by my application to sent an email for informing the client. Currently this text field is used as body of the email. In my stored procedure what i have to do is insert an html formated content into the text field so that outlook can easily show the content in table format.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 23694828
>>Is that a solution or a fact?<<
It is a fact.

>>It haven't solved my problem. I am not sure about how can I accept this fact as a solution. <<
To quote from the EE Guidelines:
<quote>
The correct answer to some questions is "You can't do that."
Sometimes, you will get an answer that isn't what you want to read, but it still may be the correct answer, and you should award points to the Expert that gave you that answer.
</quote>
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 23694944
As reb73 has implied you cannot do that using SQL Server without resorting to :using any external software" or OSQL/ISQL or if you like living dangerously perhaps using the sp_OA* extended Stored Procedures. See this link I posted nearly 5 years ago:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_20911246.html

And this one using undocumented functions:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21086593.html

And a great contribution from Hilaire:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21124599.html?

This shows some of the pitfalls of the sp_OA functions:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_20946178.html

Again none of this can be accomplished with T-SQL alone.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question