Solved

Assigning value of EXEC result to variable

Posted on 2008-10-16
2
1,071 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

705 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