Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bcp out a few columns instead of all the columns? (Sybase)

Tags:

sybase

sap-ase

How to bcp out only a few columns from a Sybase (Adaptive Server Enterprise/15.7.0) table? The following is the Sybase bcp help screen. It doesn't accept an SQL as input. I want to bcp out all the columns of the unique indexes for many tables. Or is there any alternative way?

usage: bcp [[db_name.]owner.]table_name[:slice_num] [partition pname] {in | out}
 [filename]
        [-m maxerrors] [-f formatfile] [-e errfile] [-d discardfileprefix]
        [-F firstrow] [-L lastrow] [-b batchsize]
        [-n] [-c] [-t field_terminator] [-r row_terminator]
        [-U username] [-P password] [-I interfaces_file] [-S server]
        [-a display_charset] [-z language] [-v]
        [-i input_file] [-o output_file]
        [-A packet size] [-J client character set]
        [-T text or image size] [-E] [-g id_start_value] [-N] [-W] [-X]
        [-M LabelName LabelValue] [-labeled]
        [-K keytab_file] [-R remote_server_principal] [-C]
        [-V [security_options]] [-Z security_mechanism] [-Q] [-Y]
        [-y sybase directory] [-x trusted.txt_file]
        [--clienterr errfile] [--maxconn maximum_connections]
        [--show-fi] [--hide-vcc]
        [--colpasswd [[[db_name.[owner].]table_name.]column_name [password]]]
        [--keypasswd [[db_name.[owner].]key_name [password]]]
        [--initstring ASE initialization string] [--quoted-fname]

The version is Adaptive Server Enterprise/15.7.0/EBF 20305 SMP ESD#01 Refresh#2/P/x86_64/Enterprise Linux//2927/64-bit/FBO/Fri Jun 22 09:38:01 2012

like image 930
ca9163d9 Avatar asked Jan 01 '26 02:01

ca9163d9


1 Answers

If you are using Sybase ASE prior to version 15.5, then your best option is to create views on the tables that match the columns you wish to extract, then you can bcp out of those views.

create view titles_view 
as select title, type, price, pubdate 
from titles

bcp mydatabase..titles_view out titles_view -Uusername -Sservername -n

If you are using SAP Sybase ASE 15.5 or newer, you can use the output command to output the results of a select statement to a file.

select *
from employee
go
output to employee.txt
format ASCII

The syntax and options for output can be found here: Sybase ASE Reference Manual: Commands

like image 56
Michael Gardner Avatar answered Jan 05 '26 05:01

Michael Gardner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!