We help IT Professionals succeed at work.

Store XML RAW result into a temp table / string variable

renjitkumar
renjitkumar asked
on
Medium Priority
948 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.
Comment
Watch Question

Commented:
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..

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
SQL 2005 supports it due to the availability of the new XML datatype, which is not available in SQL 2000
CERTIFIED EXPERT
Top Expert 2012

Commented:
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.

Author

Commented:
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?

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>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>
CERTIFIED EXPERT
Top Expert 2012

Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.