473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server 2005 - BULK INSERT

I'm trying to import data from flat file in table and have few
problems.

1. Field Delimiter is ',' (comma). If ',' occurs in quoted
string it is still treated as field delimiter. This is BUG or ?
2. In table I have datetime field that can be null, but bulk
insert reports error if in flat file is null or ''. It's OK only when
real date is specified.

Table:
create table AttachmentList (
Code integer not null,
ClassID integer null,
Description varchar(200) null,
ValidUntil datetime null,
constraint PK_ATTACHMENTLI ST primary key (Code))

flat file.

1,13,'Naputak, CU 261098', ''
Thanks in advance

Davor

Sep 4 '06 #1
3 7671
Davor (ds***@yahoo.co m) writes:
I'm trying to import data from flat file in table and have few
problems.

1. Field Delimiter is ',' (comma). If ',' occurs in quoted
string it is still treated as field delimiter. This is BUG or ?
No, it is by design. BCP does try to guess what you are up to. If you
say comma is a delimiter, then comma is a delimiter. The quotes are then
part of the data.

You will need to specify a format file. Judging from the sample row you
posted, that format file should look like this:

8.0
4
1 SQLCHAR 0 0 "," 1 col1 ""
2 SQLCHAR 0 0 ",'" 2 col2 ""
3 SQLCHAR 0 0 "', '" 3 col3 ""
4 SQLCHAR 0 0 "'\r\n" 4 col4 ""

That is, any quote or space that serves as a delimiter must be specified
as such. BCP has no built-in rules. (Essentially BCP treats all input
as binary data.)
2. In table I have datetime field that can be null, but bulk
insert reports error if in flat file is null or ''. It's OK only when
real date is specified.
'' is not a legal date. If you consistently use it as a delimiter, you
should specify it in the format file. If you use it inconsistently, you
have a problem.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 4 '06 #2
Hi
BULK INSERT does not have a method to define quoted strings, therefore you
would also have the quotes within the column data. It is not a BUG it is
just that the functionality does not extend that far. If you want to import
this file try using the Import Wizard and DTS. If you want to request this
in a future version you may want to vote for it at
https://connect.microsoft.com/SQLSer...dbackID=127032

John

"Davor" <ds***@yahoo.co mwrote in message
news:44******** ******@news.t-com.hr...
I'm trying to import data from flat file in table and have few
problems.

1. Field Delimiter is ',' (comma). If ',' occurs in quoted
string it is still treated as field delimiter. This is BUG or ?
2. In table I have datetime field that can be null, but bulk
insert reports error if in flat file is null or ''. It's OK only when
real date is specified.

Table:
create table AttachmentList (
Code integer not null,
ClassID integer null,
Description varchar(200) null,
ValidUntil datetime null,
constraint PK_ATTACHMENTLI ST primary key (Code))

flat file.

1,13,'Naputak, CU 261098', ''
Thanks in advance

Davor

Sep 4 '06 #3
Thanks You for Your help !

Davor
Sep 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12115
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 servers using sp_addlinkedserver on both database servers. When I call the Commit API of oledb I get the following error: Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
10
4495
by: Thomas Richards | last post by:
I have two SQL Server 2000 machines. The same file is sent nightly to each server and a stored proc uses BULK INSERT to load it into a staging table for processing. Once I've bcp'ed it in, I put it into a temp table with an IDENTITY column appended to it. (I need this identity column to group by later on to remove duplicates.) ie
6
2794
by: fumanchu | last post by:
I've got to let end users (really just one person) load billing batch files into a third party app table. They need to specify the billing cycle name, the batch name, and the input file name and then I can use these values to execute a SQL Server stored procedure to load them into the batch table from the input file (the stored procedure uses Dynamic SQL to Bulk Insert the file to a temp table then processes it into the final table.) My...
3
33230
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 poor: it takes more than 6 hours to finish the loading. So could I make use of the bulk-insert mechanism of SQL Server to reduce the loading time in C# codes? or other performance improvement solutions?
18
6709
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that I've already created on my computer. Whenever I go to open the script file (whose icon shows that it's a SQL Server Query File and I've got the file type set to open with SQLWB - SQL Server Management Studio), the file opens in Notepad instead of...
2
6948
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
19
3347
by: dunleav1 | last post by:
I built a test job that loads data into the database. I get great performance with Oracle and I'm trying to tune Sql Server to get the same type of performance. Based on system monitoring it looks like an I/O issue. So I started investigating based on sql server perfromance tuning technical reference. Here are my system monitor findings: The system monitor shows during my job:
9
21824
by: cabrenner | last post by:
I am new to SQL Server, and migrating part of an Access application to SSE. I am trying to insert a comma delimited file into SSE 2005. I am able to run a BULK INSERT statement on a simple file, specifying the field (,) and row (\n) terminators. I can also do the same with a format file. Here is the problem. My csv file has 185 columns, with a mixture of datatypes. Sometimes, a text field will contain the field delimiter as part of...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.