Solved

Assigning value of EXEC result to variable

Posted on 2008-10-16
2
1,067 Views
Last Modified: 2010-04-21
Hi,

I want to turn the path to xml file into a variable.
So, this line
SET @xmlDoc = ( SELECT * FROM OPENROWSET ( BULK 'pathtoxml.xml', SINGLE_CLOB ) AS xmlData)
 must be
SET @xmlDoc = ( SELECT * FROM OPENROWSET ( BULK @xmlPath, SINGLE_CLOB ) AS xmlData)

I tried to create a dynamic query:
 
      Set @Sql = 'SELECT * FROM OPENROWSET ( BULK '''+@xmlPath+''', SINGLE_CLOB ) as T(xmlData)'
            exec sp_executesql @Sql, N'@res XML OUTPUT' , @xmlDoc OUTPUT

       -- this line should return the number of tags under DATA
       SELECT @xmlDoc.value('count(/XML/DATA/*)','INT')

But unfortunately @xmlDoc does not return the xml data that I am expecting.

Am I missing something?

0
Comment
Question by:JaimeJegonia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 22728745
try
Set @Sql = 'SET @res = (SELECT * FROM OPENROWSET ( BULK '''+@xmlPath+''', SINGLE_CLOB ) as T(xmlData))'
0
 

Author Closing Comment

by:JaimeJegonia
ID: 31506629
Thanks!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

726 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