Solved

bulk insert with format file with datetime

Posted on 2003-12-01
9
1,160 Views
Last Modified: 2012-05-04
How do you specify the datetime format in format files for bulk insert?

I have some tables that I need to import, and I can easily do that with a simple bulk insert, but in this case I need to map fields because data is not identical in format with the table.

Here my problems start. No matter how I try, I can not create a date format that can be inserted when I use a format file.

0
Comment
Question by:Custode
[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
  • 4
9 Comments
 
LVL 6

Expert Comment

by:lausz
ID: 9850401
Can you post a little sample  .?
0
 

Author Comment

by:Custode
ID: 9850487
An example :

Format file

8.0
4
1       SQLINT        0       4       "|||"                     1     t2id          ""
2       SQLCHAR       0       20      "|||"                     2     t2_shopid     Danish_Norwegian_CI_AS
3       SQLCHAR       0       100     "|||"                     3     t2_f1         Danish_Norwegian_CI_AS
4       SQLDATETIME   0       8       "||||"                    4     t2_f3         ""


Data file

10|||||||||2002/01/01||||

0
 
LVL 6

Expert Comment

by:lausz
ID: 9850538
I don't understand ..

is this the field t2id = 10|||
t2_shopid |||
t2_f1 = |||
t2_f3 2002/01/01||||

????

What are you using as column delimiter ?
What is the destination table design ?



0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:Custode
ID: 9850886
Create table t2 (
 t2id int primary key not null,
 t2_shopid varchar(20) null,
 t2_f1 varchar(100) null,
 t2_f3 datetime null
)

This is just a table I created to find a solution to the problem. It's easier to play with than a table with 400 fields.

FieldTerminator is '|||' and RowTerminator is '||||'

As I mentioned, it works fine if I use

bulk insert t2 from 'C:\test\t2.txt' with
 (
  FieldTerminator = '|||',
  RowTerminator = '||||'
)

but it doesn't work if I use a format file like the one above.

 
0
 
LVL 6

Expert Comment

by:lausz
ID: 9851542
I try your example with your bulk insert and the datetime works ok.
What kind of problem do you have.

In your example I have the fields (t2_shopid  and t2_f1) with nulls and the other info ok.
0
 

Author Comment

by:Custode
ID: 9851672
Did you do like

bulk insert t2 from 'c:\tmp\t2.txt' with
(
 formatfile = 'c:\tmp\t2.fmt'
)

and make it work?
0
 
LVL 6

Expert Comment

by:lausz
ID: 9851877
TRY ONLY CHANGING IN LINE 4 FROM .FMT

4       SQLCHAR       0       10      "||||"                    4     t2_f3         ""

I think it works
0
 
LVL 6

Accepted Solution

by:
lausz earned 500 total points
ID: 9852052
Did you try ?
0
 

Author Comment

by:Custode
ID: 9852168
Yes, I tried, and It worked.

Thanks.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

691 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