473,405 Members | 2,415 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,405 software developers and data experts.

Bulk Insert - Dynamic Errorfile Filename

2
I am trying to dynamically create the errorfile name with the date the error occured. The error occurs at ERRORFILE = @errorfilename

Is this possible?

Here is the script I have so far...

-------------------------------------------------------------------------------------------------------------------

USE Temp

GO

DECLARE @errorfilename text

SET @errorfilename = 'c:\rx_data_repos_ERROR_' + CONVERT(text, GETDATE())

BULK INSERT downloaded
FROM 'c:\rx_data_repos.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n',
CHECK_CONSTRAINTS,
FIRE_TRIGGERS,
TABLOCK,
ERRORFILE = @errorfilename)
)
Mar 1 '08 #1
2 5513
ck9663
2,878 Expert 2GB
I am trying to dynamically create the errorfile name with the date the error occured. The error occurs at ERRORFILE = @errorfilename

Is this possible?

Here is the script I have so far...

-------------------------------------------------------------------------------------------------------------------

USE Temp

GO

DECLARE @errorfilename text

SET @errorfilename = 'c:\rx_data_repos_ERROR_' + CONVERT(text, GETDATE())

BULK INSERT downloaded
FROM 'c:\rx_data_repos.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n',
CHECK_CONSTRAINTS,
FIRE_TRIGGERS,
TABLOCK,
ERRORFILE = @errorfilename)
)

You might need to create a dynamic t-sql for this one

declare @sqlstmt varchar(150)

set @sqlstmt = 'BULK INSERT downloaded
FROM ''c:\rx_data_repos.txt''
WITH
(
FIELDTERMINATOR = ''|'',
ROWTERMINATOR = ''\n'',
CHECK_CONSTRAINTS,
FIRE_TRIGGERS,
TABLOCK,
ERRORFILE = ' + @errorfilename + ')'

exec @sqlstmt

I did not check if you BULK INSERT syntax is correct. But I hope you got the idea of what am trying to suggest.

-- CK
Mar 2 '08 #2
chompy
2
Thanks CK,

This is what I ended up with.

DECLARE @sqlstmt varchar(500),
@errorfilename varchar(150),
@TodayDate as varchar(40),
@TodayHour as varchar(40),
@TodayMinu as varchar(40)

SELECT @TodayDate = CONVERT(varchar(10), GETDATE(), 112)
SELECT @TodayHour = DATEPART(hh,GETDATE())
SELECT @TodayMinu = DATEPART(mi,GETDATE())

SET @errorfilename = 'c:\rx_data_repos_Error_' +
@TodayDate +
'_' +
@TodayHour +
@TodayMinu +
'.txt'

SET @sqlstmt = 'BULK INSERT tmp_Rx_Data_Repos
FROM ''c:\rx_data_repos.txt''
WITH (FIELDTERMINATOR = ''|'',
ROWTERMINATOR = ''\n'',
ERRORFILE = ' + '''' +@errorfilename + '''' +')'

EXECUTE (@sqlstmt)
Mar 2 '08 #3

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

Similar topics

7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
2
by: Mike Husler | last post by:
We have created CSV files on HPUX 11.0 and transferred them via ASCII ftp to our SQL Server machine file store to load large amounts for data using the BULK INSERT command. This is the command: ...
1
by: Mike | last post by:
I am trying to use the 'Bulk Insert' command to load a data file into a MS-SQL db. The line I am using is: Bulk Insert SVC_Details From "C:\XFILE.TXT" With (FieldTerminator = ',') I have tried...
3
by: moonriver | last post by:
Right now I develop an application to retrieve over 30,000 records from a binary file and then load them into a SQL Server DB. So far I load those records one by one, but the performance is very...
0
by: m31hu1 | last post by:
Hi all, I'm new to this forum... I'm trying to let sql store data from a text file, but the data won't display... what am i missing here? Your help is greatly appreciated. create table <?php...
0
by: Jason | last post by:
Hi I wanted to bounce an Idea off you guys. I'm not sure if it's possible or even how to implement it .. or possibly if I'm trying to re-invent the wheel. Our users currently use excel and a...
0
by: teddymeu | last post by:
Hi Guys, since I've done nothing but ask questions these last few weeks to get my first application up and running I thought it was about time to share the wealth and help out a newbie like me since...
0
by: NickW | last post by:
I have written a stored procedure that is used to load data into a SQL Server 2000 and 2005 databases from some 40ish different text files. One of the text files is loading all of the rows apart from...
1
by: John A Grandy | last post by:
Since I want BULK INSERT to fail on unique key violations , I set MAXERRORS=0 But how to determine which row of the flat-file contains the duplicate ? Apparently, ERRORFILE is not created 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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.