Solved

bulk insert with format file with datetime

Posted on 2003-12-01
9
1,133 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL: Episode III - Revenge of The Dude 24 53
Flattening heirachies 3 31
transaction in asp.net, sql server 6 33
access query to sql server 3 21
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

810 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