Go Back   Talk Root - PC Hardware, Software and Web Development forums > System Administration > Database Servers > SQL Server > SQL Server 2



Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
  #1  
Old 03-23-2004, 01:20 PM
ajmister
Guest
 
Posts: n/a
Default Newbie needs help with BCP out file

Hi
I am running the following BCP command to extract data from a table test_stu

C:\test>bcp temp..test_stu out c:\test\out\test.rpt /S SERVER /U USER /P
password /f c:\test\test.fmt

create table test_stu
(s_name char (6)
s_year int (4)
s_mean varchar (10)
s_median varchar (10)
s_standard_dev varchar (10)
s_rec_no smallint (2)
s_number_up varchar (10)
s_number_down varchar (10)
)


format file
test.fmt

8.0
8
1 SQLCHAR 0 6 "/t" 1 s_name ""
2 SQLCHAR 0 8 "/t" 2 s_year ""
3 SQLCHAR 0 5 "/t" 3 s_mean ""
4 SQLCHAR 0 5 "/t" 4 s_median ""
5 SQLCHAR 0 5 "/t" 5 s_standard_dev ""
6 SQLCHAR 0 4 "/t" 6 s_record_no ""
7 SQLCHAR 0 4 "/t" 7 s_number_up ""
8 SQLCHAR 0 4 "\r\n" 8 s_number_down ""


I get a tab formatted output file. Is it possible to create a fixed field
output file using the format file eg.

Label length position
s_name 6 1 - 7

s_year 4 8 - 11
s_mean 5 13 - 17

s_median 5 19 - 23

s_standard_dev. 5 25 - 30

s_record_no 4 31 - 34

s_number_up 4 36 - 39

s_number_down 4 41 - 44



Ajay




Reply With Quote
  #2  
Old 03-23-2004, 03:23 PM
Erland Sommarskog
Guest
 
Posts: n/a
Default Re: Newbie needs help with BCP out file

ajmister (ajmister@optonline.net) writes:
> format file
> test.fmt
>
> 8.0
> 8
> 1 SQLCHAR 0 6 "/t" 1 s_name ""
> 2 SQLCHAR 0 8 "/t" 2 s_year ""
> 3 SQLCHAR 0 5 "/t" 3 s_mean ""
> 4 SQLCHAR 0 5 "/t" 4 s_median ""
> 5 SQLCHAR 0 5 "/t" 5 s_standard_dev ""
> 6 SQLCHAR 0 4 "/t" 6 s_record_no ""
> 7 SQLCHAR 0 4 "/t" 7 s_number_up ""
> 8 SQLCHAR 0 4 "\r\n" 8 s_number_down ""
>
>
> I get a tab formatted output file. Is it possible to create a fixed field
> output file using the format file eg.


Yes. Specify "" as the column terminator, and specify the column lengths
appropriately. In the example of how your fixed-length file would look
like, you have s_year as 4 characters long, but the in the format file
above, you have 8.


--
Erland Sommarskog, SQL Server MVP, [email]sommar@algonet.se[/email]

Books Online for SQL Server SP3 at
[url]http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp[/url]
Reply With Quote
Reply

Bookmarks
Sponsored Links
FatCow $88 Plan for $66 only Host Unlimited Domains on 1 Account Professional Hosting from Just Host


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the best web site for file share? Bangkok TalkRoot Lounge 1 05-15-2009 01:06 AM
Deleting a Directory from Your Linux Hosting Account Using the File Manager endidoya Linux Discussion 0 02-25-2008 12:49 AM
Deleting a Directory from Your Linux Hosting Account Using the File Manager endidoya Linux Discussion 0 02-25-2008 12:49 AM
Opening Access file arppt01 Advocacy 0 03-31-2007 07:35 AM
chkdsk exit codes 'whihc one is the code?' lanciaHF Windows XP 0 11-15-2006 09:00 AM


All times are GMT -7. The time now is 10:41 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
© 2008 TalkRoot.com