473,396 Members | 1,864 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,396 software developers and data experts.

BCP Format File

A format file provides a way to bulk copy data selectively from a data
file to an instance of SQL Server. This allows the transfer of data to
a table when there is a mismatch between fields in the data file and
columns in the table.
I take it this assumes the number of fields in the data file will
always be constant. What if it is not?
My table has two columns but my datafile may have 2 to 4 columns and I
want to always select only the first two. Is there a way to set up the
format file to accomplish that?
Jul 20 '05 #1
3 10992
Rathtap (am****@yahoo.com) writes:
A format file provides a way to bulk copy data selectively from a data
file to an instance of SQL Server. This allows the transfer of data to
a table when there is a mismatch between fields in the data file and
columns in the table.
I take it this assumes the number of fields in the data file will
always be constant. What if it is not?
My table has two columns but my datafile may have 2 to 4 columns and I
want to always select only the first two. Is there a way to set up the
format file to accomplish that?


Don't know off hand. Can you post a sample of the input file, and a CREATE
TABLE statement for your table?

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
This is the table:
CREATE TABLE [dbo].[CT_RATE_TEMP] (
[code] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[CODERATE] [smallmoney] NULL ,
[CODERATE2] [smallmoney] NULL ,
[CODERATE3] [smallmoney] NULL ,
[CODERATE4] [smallmoney] NULL
) ON [PRIMARY]
GO

And here is the import file:
36415 25.00
52759 24.50
52760 12.77
52775 24.03
74285 16.88
74436 7.84
80003 7.58
80004 8.00
80005 8.92
80006 8.94
80007 9.32
80008 9.66
80009 9.90
80010 9.90
80011 10.08
80012 10.29
Here I would like Col1 of the file to map to the Code field and Col2
to CodeRate. CODERATE2,CODERATE3 and CODERATE4 should be null.

On the other hand there may be the following file to import where all
fields match, then there is no problem:
52759 24.50 24.50 24.50
52760 12.77 12.77 12.77
52775 24.03 24.03 24.03
74285 16.88 16.88 16.88
74436 7.84 7.84 7.84
80003 7.58 7.58 7.58
80004 8.00 8.00 8.00
80005 8.92 8.92 8.92
80006 8.94 8.94 8.94
80007 9.32 9.32 9.32
80008 9.66 9.66 9.66
80009 9.90 9.90 9.90
80010 9.90 9.90 9.90
80011 10.08 10.08 10.08
80012 10.29 10.29 10.29
80016 12.05 12.05 12.05
80018 12.14 12.14 12.14
80019 12.61 12.61 12.61
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn********************@127.0.0.1>...
Rathtap (am****@yahoo.com) writes:
A format file provides a way to bulk copy data selectively from a data
file to an instance of SQL Server. This allows the transfer of data to
a table when there is a mismatch between fields in the data file and
columns in the table.
I take it this assumes the number of fields in the data file will
always be constant. What if it is not?
My table has two columns but my datafile may have 2 to 4 columns and I
want to always select only the first two. Is there a way to set up the
format file to accomplish that?


Don't know off hand. Can you post a sample of the input file, and a CREATE
TABLE statement for your table?

Jul 20 '05 #3
mgran
1
try adding default values to the null fields
Jul 24 '06 #4

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

Similar topics

1
by: Query Builder | last post by:
I am new to BCP. Can anyone help me understand this? I tried searching the BOL but it doesnt show much help on syntex. Lets say I have a simple table and want to out put the records into a file....
2
by: Pat | last post by:
Here is my problem that I am having with a current project. I went and backed up all my hard drives to DVD's. After backing up the drives, I used a batch file to get all the file names from the...
2
by: KR | last post by:
I am trying to copy the data in excel file into a table using the bcp and this is the code that I have. However the bcp utility does not seem to create a format file, which I thought it should...
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
6
by: Ted | last post by:
I used bcp to produce the apended format file. How can it be modified to recognize the quotes that surround the text fields and not insert the quotes along with the text? Invariably, the first...
2
by: leahf via AccessMonster.com | last post by:
I upgraded from Access97 to Access2002 last year. I just noticed that the default file format is Access 2000. Can that be the reason that I sometimes get "Microsoft Access has encountered..."...
3
by: karthikla | last post by:
Hi Experts, Could you please help me on how to get access 2002 file format exactly while doing conversion from Access 97 file format by DBEngine.CompactDatabase() function? Code: Private...
2
by: johnperl | last post by:
i am working on the script as below, i want an output according to the format. i am trying to put everything in one loop but cannot figure out the way to do so. could anyone please help me with this....
6
by: aagarwal8 | last post by:
Hi, I am trying to write the contents of a textbox to a file in binary format. My code looks like this... private void btnWriteToFile_Click(object sender, EventArgs e) { FileStream fs =...
5
by: sonu | last post by:
hey good morning ...... how to convert a video file in .flv format in php for linux hosting......is there any package whis provide this facility . Can i use ffmpeg for linux hosting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.