Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2009, 02:17 PM
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bulk uploading a large xml file into single column in table

Hi members,

I want to bulk upload a large xml file into a single column of a table. I tried the below code but varchar variable supports only upto 8000 characters and my file contents exceeds the length.Is there any way to accomplish in sql 2000?

Code:
 
DECLARE @FileName varchar(255)
DECLARE @ExecCmd VARCHAR(255)
DECLARE @y INT
DECLARE @x INT
DECLARE @FileContents VARCHAR(8000)
CREATE TABLE #tempXML(PK INT NOT NULL IDENTITY(1,1), ThisLine VARCHAR(255))
SET @FileName = 'C:\Temp\CurrentSettings.xml'
SET @ExecCmd = 'type ' + @FileName
SET @FileContents = ''
INSERT INTO #tempXML EXEC master.dbo.xp_cmdshell @ExecCmd
SELECT @y = count(*) from #tempXML
SET @x = 0
WHILE @x <> @y
    BEGIN
        SET @x = @x + 1
        SELECT @FileContents = @FileContents + ThisLine from #tempXML WHERE PK
 = @x
    END
SELECT @FileContents as FileContents
DROP TABLE #tempXML
Thanks
 
Old March 13th, 2009, 05:15 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a staging table with only one TEXT or NTEXT column.

DECLARE @cmd NVARCHAR(4000)
SET @cmd ='BULK INSERT dbo.MyTable
FROM '
+QUOTENAME(@fileName,'''')+'
WITH (
BATCHSIZE = 1,
CODEPAGE = ''ACP'',
FIELDTERMINATOR = ''0x00'',
ROWTERMINATOR = ''\n\n''
)'
EXEC (@cmd)

then update your original table with the value from the staging table.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while uploading large image file webnet ASP.NET 2.0 Basics 1 November 12th, 2007 09:32 AM
Uploading Large Files to a Doc Lib viccoleman SharePoint Admin 1 May 15th, 2006 01:13 PM
Converting large columns into a single row rahulpokharna SQL Server 2000 3 January 10th, 2006 02:14 AM
re: modify the column in a xml file ramya General .NET 1 January 20th, 2005 04:50 AM
uploading large files a 4Mb limit seems present! Grahame2003 C# 2 December 4th, 2003 05:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.