?
Solved

Need help with this Bulk Insert stored proc.

Posted on 2003-03-19
5
Medium Priority
?
300 Views
Last Modified: 2006-11-17
hallo all,
well I have following SP:
CREATE PROCEDURE [dbo]._blkIns_FlatFile
@FileName varchar
AS
DECLARE @FullPath varchar
SET @FullPath  = 'D:\inetpub\ftproot\' + @FileName
BULK INSERT m1.dbo.[User]
FROM @FullPath
WITH
(CODEPAGE = 'ACP' , FIELDTERMINATOR ='\t' , ROWTERMINATOR ='\n' )
GO
but allways reciving an erorr in line 7 (FROM @FullPath).
What I want is to upload file and give a name of file to stored proc
and then make an bulk insert. Question is what is wrong here, and is this possible
to create a dynamic name of the file to insert from.
Erorr messages is Bad syntax in near from @Fullpath in Line 7.
Hope someone has some idea.
Thanx a lot
Regards
Zeljko
0
Comment
Question by:Zelja
[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
5 Comments
 
LVL 12

Expert Comment

by:ill
ID: 8165702
CREATE PROCEDURE [dbo]._blkIns_FlatFile
@FileName varchar
AS
DECLARE @FullPath varchar
SET @FullPath  = 'D:\inetpub\ftproot\' + @FileName
declare text nvarchar(4000)
sert @text='
BULK INSERT m1.dbo.[User]
FROM ' +@FullPath +'
WITH
(CODEPAGE = ''ACP'' , FIELDTERMINATOR =''\t'' , ROWTERMINATOR =''\n'' )'
exec ( @text)
GO
0
 

Accepted Solution

by:
ashishjj earned 600 total points
ID: 8165959
Hi,

   Try this


CREATE PROCEDURE [dbo]._blkIns_FlatFile
@FileName varchar
AS

DECLARE @FullPath varchar
DECLARE @tstrQuery nvarchar(4000)

SET @FullPath  = 'D:\inetpub\ftproot\' + @FileName

SELECT @tstrQuery = ' BULK INSERT m1.dbo.[User] ' +
               ' FROM ''' + @FullPath + '''' +
               ' WITH (CODEPAGE = ''ACP'' , FIELDTERMINATOR =''\t'' , ROWTERMINATOR =''\n'' )'


-- execute the query
EXEC sp_executesql  @tstrQuery


GO

Ashish
0
 
LVL 9

Expert Comment

by:xenon_je
ID: 8166141
So all you can do is to use dynamic queries, because bulk insert requests you to fill the filename, not to use a variable there. (so create a variable in which you put the entire query, then execute it with
exec('string query...')
The solutions described above should work
0
 

Expert Comment

by:CleanupPing
ID: 9275740
Zelja:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Author Comment

by:Zelja
ID: 9389688
thx a lot people
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

777 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