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 May 25th, 2004, 01:48 AM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default bulk insert error - help needed!!

CREATE proc spImportRegData

AS

CREATE TABLE #T
(o varchar(8000))
insert into #T
EXEC MASTER..xp_cmdshell 'dir D:\Site\log\*.rpt'
delete from #T WHERE o not like '%batch_registration%'
delete from #T WHERE o IS NULL
select right(o,45) from #T

DECLARE @filename varchar(100)
DECLARE @sql varchar(5000)

DECLARE fileCursor Cursor for
SELECT right(o,45) AS o FROM #T
OPEN fileCursor

FETCH NEXT FROM fileCursor INTO @filename
while @@fetch_status=0
Begin
SET @sql = 'BULK INSERT adp2sql.dbo.[RegisteredSubscribers] FROM ''D:\Site\log\' + @filename + ''' WITH (FIELDTERMINATOR =''|'',ROWTERMINATOR =''\n'')'
print @sql
exec @sql
FETCH NEXT FROM fileCursor INTO @filename
END
Close fileCursor
Deallocate fileCursor
-----------------------------------------------------

The error i get is;

(9 row(s) affected)


(5 row(s) affected)


(3 row(s) affected)


(1 row(s) affected)

BULK INSERT adp2sql.dbo.[RegisteredSubscribers] FROM 'D:\Site\log\batch_registration_update_20040521_20 5002.rpt' WITH (FIELDTERMINATOR ='|',ROWTERMINATOR ='\n')
Server: Msg 203, Level 16, State 2, Procedure spImportRegData, Line 25
The name 'BULK INSERT adp2sql.dbo.[RegisteredSubscribers] FROM 'D:\Site\log\batch_registration_update_20040521_20 5002.rpt' WITH (FIELDTERMINATOR ='|',ROWTERMINATOR ='\n')' is not a valid identifier.


Can anyone help? i have been battling with this and i cant seem to see a way round it...

thanks

 
Old May 25th, 2004, 09:35 AM
Authorized User
 
Join Date: Jun 2003
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try replacing

exec @sql

with

exec sp_sqlexec @sql
 
Old May 25th, 2004, 04:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

when you execute a TSQL string you should wrap that @sql variable with brackets () like...

Exec (@sql)

This is what sp_sqlexec does.

But this is not the same with executing a stored proc.

Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Insert snufse SQL Server 2000 9 December 17th, 2007 07:53 AM
bulk insert hymavathy_kr VB Databases Basics 1 May 17th, 2007 07:47 AM
Error Handling in Bulk Insert starnet SQL Server 2000 0 October 12th, 2006 03:27 AM
XML Bulk Load Help Needed JKJKJK XML 1 February 6th, 2004 09:06 AM





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