473,418 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

BULK xml file using a path parameter

344 100+
Hi,

I'm bulking an xml file using BULK statement to an XML variable, like this:
Expand|Select|Wrap|Line Numbers
  1. DECLARE @xmlDoc XML
  2. SET @xmlDoc = (
  3.   SELECT * FROM OPENROWSET (
  4.     BULK 'D:\root.xml', SINGLE_CLOB
  5.   ) AS xmlData
  6. )
  7. SELECT @xmlDoc
I'm trying to set 'D:\root.xml' to be a paramater @filepath. But I'm getting a parsing problem, that it expects to be string or Text-LEX..!!

Here is what I did:
Expand|Select|Wrap|Line Numbers
  1. (
  2. @filepath nvarchar(255)
  3. )
  4. SET @xmlDoc = (
  5.   SELECT * FROM OPENROWSET (
  6.     BULK @filepath, SINGLE_CLOB
  7.   ) AS xmlData
  8. )
  9. SELECT @xmlDoc
Thanks in advanced!
Sep 26 '10 #1
1 11474
Bassem
344 100+
Hi,

After a massive searching I found a perfect solution:

http://www.sqlservercentral.com/Foru...475-338-1.aspx

Expand|Select|Wrap|Line Numbers
  1. DECLARE @results table (result xml)
  2. --Build the Dynamic SQL Statement to get the data from the xml file
  3. SET @sqlstmt= 'SELECT * FROM OPENROWSET ( BULK ''' + @filename + ''', SINGLE_CLOB )AS xmlData'
  4.  
  5. -- Insert the results of the dynamic SQL Statement into the temporary table variable.
  6. INSERT INTO @results EXEC (@sqlstmt)
  7.  
  8. DECLARE @xmlDoc XML
  9. SELECT @xmlDoc = result FROM @results
Thanks
Sep 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: brian.fairchild | last post by:
I have a downloader page in my asp.net application that looks at a session variable to get the path to the file, checks it then downloads it using the Response object. When the "File Download"...
1
by: IMRAN | last post by:
I have created a component which parses some flat files and stores in Sql database. Now I want to move that COM object to database server. Now the scenario will be like this : 1) ASP page...
0
by: Shawn Ferguson | last post by:
With the help of you, I've been able to successfully load my database with the contents of a "comma" delimited file. It loads about 5000 records in about 3 seconds:) Now I have another problem. ...
4
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another...
2
by: contractsup | last post by:
Environment: $ uname -a AIX <withheld2 5 000100614C00 $ db2level DB21085I Instance "<withheld>" uses "32" bits and DB2 code release "SQL08024" with level identifier "03050106"....
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
3
by: brook | last post by:
hey all - i´m new to php and having trouble writing a simple code which should create a file. here is the most simplified version: <?php $content = "my content"; $path = "test.txt";...
0
by: Alexnb | last post by:
Okay, so what I want my program to do it open a file, a music file in specific, and for this we will say it is an .mp3. Well, I am using the system() command from the os class. The problem I am...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
4
by: buntyp | last post by:
Hello Friends I am new to this programing world so please help me I want to creat an application that CAN COPY FILES OF PARTICULAR MONTH AS PER ITS LAST WRITEN DATE (LAST MODIFIYED DATE) FOR...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.