Solved

bulk insert with format file with datetime

Posted on 2003-12-01
9
1,097 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
Comment Utility
Can you post a little sample  .?
0
 

Author Comment

by:Custode
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Custode
Comment Utility
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 6

Expert Comment

by:lausz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Did you try ?
0
 

Author Comment

by:Custode
Comment Utility
Yes, I tried, and It worked.

Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

744 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now